diff options
| author | 2024-02-20 09:13:36 -0400 | |
|---|---|---|
| committer | 2024-02-20 09:13:36 -0400 | |
| commit | 134a7df8206aa66ca7b0abbc7f31f08410b502d2 (patch) | |
| tree | e3c520dce4f529de5290bc145847e78fb5583bee /src/main.zig | |
| parent | Cleaned up directory structure (diff) | |
| download | zg-134a7df8206aa66ca7b0abbc7f31f08410b502d2.tar.gz zg-134a7df8206aa66ca7b0abbc7f31f08410b502d2.tar.xz zg-134a7df8206aa66ca7b0abbc7f31f08410b502d2.zip | |
Replaced ccc_map with table. 20ms faster
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main.zig b/src/main.zig index 019076a..946ae01 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -5,10 +5,12 @@ const std = @import("std"); | |||
| 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 | // const ascii = @import("ascii"); | 10 | // const ascii = @import("ascii"); |
| 11 | // const ascii = std.ascii; | 11 | // const ascii = std.ascii; |
| 12 | // const norm = @import("ziglyph").Normalizer; | ||
| 13 | const norm = @import("Normalizer"); | ||
| 12 | 14 | ||
| 13 | pub fn main() !void { | 15 | pub fn main() !void { |
| 14 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 16 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| @@ -18,6 +20,9 @@ pub fn main() !void { | |||
| 18 | const input = try std.fs.cwd().readFileAlloc(allocator, "data/lang_mix.txt", std.math.maxInt(u32)); | 20 | const input = try std.fs.cwd().readFileAlloc(allocator, "data/lang_mix.txt", std.math.maxInt(u32)); |
| 19 | defer allocator.free(input); | 21 | defer allocator.free(input); |
| 20 | 22 | ||
| 23 | var n = try norm.init(allocator); | ||
| 24 | defer n.deinit(); | ||
| 25 | |||
| 21 | // var iter = GraphemeIterator.init(input); | 26 | // var iter = GraphemeIterator.init(input); |
| 22 | // var iter = CodePointIterator{ .bytes = input }; | 27 | // var iter = CodePointIterator{ .bytes = input }; |
| 23 | var iter = std.mem.splitScalar(u8, input, '\n'); | 28 | var iter = std.mem.splitScalar(u8, input, '\n'); |
| @@ -28,7 +33,12 @@ pub fn main() !void { | |||
| 28 | 33 | ||
| 29 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); | 34 | // while (iter.next()) |cp| result += codePointWidth(@intCast(cp.code)); |
| 30 | // while (iter.next()) |_| result += 1; | 35 | // while (iter.next()) |_| result += 1; |
| 31 | while (iter.next()) |line| result += strWidth(line); | 36 | // while (iter.next()) |line| result += strWidth(line); |
| 37 | while (iter.next()) |line| { | ||
| 38 | var nfc = try n.nfc(allocator, line); | ||
| 39 | result += nfc.slice.len; | ||
| 40 | nfc.deinit(); | ||
| 41 | } | ||
| 32 | 42 | ||
| 33 | std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); | 43 | std.debug.print("result: {}, took: {}\n", .{ result, timer.lap() / std.time.ns_per_ms }); |
| 34 | } | 44 | } |