diff options
| author | 2024-02-17 11:31:52 -0400 | |
|---|---|---|
| committer | 2024-02-17 11:31:52 -0400 | |
| commit | 490fd008e29420e5b317fd5ef7526f3cc92ba2eb (patch) | |
| tree | 7864cae008cd64a881736fecedf12e5dd5611e83 /src/main.zig | |
| parent | GraphemeIterator ASCII optimization 3x faster (diff) | |
| download | zg-490fd008e29420e5b317fd5ef7526f3cc92ba2eb.tar.gz zg-490fd008e29420e5b317fd5ef7526f3cc92ba2eb.tar.xz zg-490fd008e29420e5b317fd5ef7526f3cc92ba2eb.zip | |
display_width tweaks
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig index bb188ff..38ba343 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | // const GraphemeIterator = @import("ziglyph").GraphemeIterator; | 3 | // const GraphemeIterator = @import("ziglyph").GraphemeIterator; |
| 4 | const GraphemeIterator = @import("Grapheme").GraphemeIterator; | 4 | // const GraphemeIterator = @import("Grapheme").GraphemeIterator; |
| 5 | // const codePointWidth = @import("ziglyph").display_width.codePointWidth; | 5 | // const codePointWidth = @import("ziglyph").display_width.codePointWidth; |
| 6 | // const codePointWidth = @import("display_width").codePointWidth; | 6 | // const codePointWidth = @import("display_width").codePointWidth; |
| 7 | // const strWidth = @import("ziglyph").display_width.strWidth; | 7 | // const strWidth = @import("ziglyph").display_width.strWidth; |
| 8 | // const strWidth = @import("display_width").strWidth; | 8 | const strWidth = @import("display_width").strWidth; |
| 9 | // const CodePointIterator = @import("CodePoint").CodePointIterator; | 9 | const CodePointIterator = @import("CodePoint").CodePointIterator; |
| 10 | 10 | ||
| 11 | pub fn main() !void { | 11 | pub fn main() !void { |
| 12 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 12 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| @@ -17,16 +17,17 @@ pub fn main() !void { | |||
| 17 | defer allocator.free(input); | 17 | defer allocator.free(input); |
| 18 | 18 | ||
| 19 | var result: usize = 0; | 19 | var result: usize = 0; |
| 20 | var iter = GraphemeIterator.init(input); | 20 | // var result: isize = 0; |
| 21 | // var iter = GraphemeIterator.init(input); | ||
| 21 | // var iter = CodePointIterator{ .bytes = input }; | 22 | // var iter = CodePointIterator{ .bytes = input }; |
| 22 | // var iter = std.mem.splitScalar(u8, input, '\n'); | 23 | var iter = std.mem.splitScalar(u8, input, '\n'); |
| 23 | 24 | ||
| 24 | var timer = try std.time.Timer.start(); | 25 | var timer = try std.time.Timer.start(); |
| 25 | 26 | ||
| 26 | // for (0..50) |_| { | 27 | // for (0..50) |_| { |
| 27 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); | 28 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); |
| 28 | while (iter.next()) |_| result += 1; | 29 | // while (iter.next()) |_| result += 1; |
| 29 | // while (iter.next()) |line| result += strWidth(line); | 30 | while (iter.next()) |line| result += strWidth(line); |
| 30 | // iter.cp_iter.i = 0; | 31 | // iter.cp_iter.i = 0; |
| 31 | // } | 32 | // } |
| 32 | 33 | ||