diff options
| author | 2024-02-13 11:07:20 -0400 | |
|---|---|---|
| committer | 2024-02-13 11:07:20 -0400 | |
| commit | 3b41b1d4e113a5319a9aa7ef1d3ab248048f2872 (patch) | |
| tree | 9513204c5fa24ac68731d46d608db4300b537abd /src | |
| parent | Not embedding file (diff) | |
| download | zg-3b41b1d4e113a5319a9aa7ef1d3ab248048f2872.tar.gz zg-3b41b1d4e113a5319a9aa7ef1d3ab248048f2872.tar.xz zg-3b41b1d4e113a5319a9aa7ef1d3ab248048f2872.zip | |
Using no_prop to short lookup
Diffstat (limited to 'src')
| -rw-r--r-- | src/gbp_gen.zig | 17 | ||||
| -rw-r--r-- | src/main.zig | 4 |
2 files changed, 18 insertions, 3 deletions
diff --git a/src/gbp_gen.zig b/src/gbp_gen.zig index fcc7aa4..afc54fc 100644 --- a/src/gbp_gen.zig +++ b/src/gbp_gen.zig | |||
| @@ -62,15 +62,20 @@ pub fn main() !void { | |||
| 62 | var blocks_map = BlockMap.init(allocator); | 62 | var blocks_map = BlockMap.init(allocator); |
| 63 | defer blocks_map.deinit(); | 63 | defer blocks_map.deinit(); |
| 64 | 64 | ||
| 65 | const no_prop = std.math.maxInt(u16); | ||
| 66 | |||
| 65 | var stage1 = std.ArrayList(u16).init(allocator); | 67 | var stage1 = std.ArrayList(u16).init(allocator); |
| 66 | defer stage1.deinit(); | 68 | defer stage1.deinit(); |
| 69 | |||
| 67 | var stage2 = std.ArrayList(u4).init(allocator); | 70 | var stage2 = std.ArrayList(u4).init(allocator); |
| 68 | defer stage2.deinit(); | 71 | defer stage2.deinit(); |
| 72 | |||
| 69 | var stage3 = std.ArrayList(Prop).init(allocator); | 73 | var stage3 = std.ArrayList(Prop).init(allocator); |
| 70 | defer stage3.deinit(); | 74 | defer stage3.deinit(); |
| 71 | 75 | ||
| 72 | var block: Block = undefined; | 76 | var block: Block = undefined; |
| 73 | var block_len: u16 = 0; | 77 | var block_len: u16 = 0; |
| 78 | |||
| 74 | for (0..0x10ffff + 1) |cp| { | 79 | for (0..0x10ffff + 1) |cp| { |
| 75 | const prop = Prop.forCodePoint(@intCast(cp)); | 80 | const prop = Prop.forCodePoint(@intCast(cp)); |
| 76 | 81 | ||
| @@ -96,7 +101,12 @@ pub fn main() !void { | |||
| 96 | try stage2.appendSlice(block[0..block_len]); | 101 | try stage2.appendSlice(block[0..block_len]); |
| 97 | } | 102 | } |
| 98 | 103 | ||
| 99 | try stage1.append(gop.value_ptr.*); | 104 | if (prop == .none) { |
| 105 | try stage1.append(no_prop); | ||
| 106 | } else { | ||
| 107 | try stage1.append(gop.value_ptr.*); | ||
| 108 | } | ||
| 109 | |||
| 100 | block_len = 0; | 110 | block_len = 0; |
| 101 | } | 111 | } |
| 102 | 112 | ||
| @@ -110,6 +120,8 @@ pub fn main() !void { | |||
| 110 | const writer = out_buf.writer(); | 120 | const writer = out_buf.writer(); |
| 111 | 121 | ||
| 112 | const prop_code = | 122 | const prop_code = |
| 123 | \\const std = @import("std"); | ||
| 124 | \\ | ||
| 113 | \\const Prop = enum { | 125 | \\const Prop = enum { |
| 114 | \\ none, | 126 | \\ none, |
| 115 | \\ | 127 | \\ |
| @@ -149,8 +161,11 @@ pub fn main() !void { | |||
| 149 | try writer.writeAll("};\n"); | 161 | try writer.writeAll("};\n"); |
| 150 | 162 | ||
| 151 | const code = | 163 | const code = |
| 164 | \\const no_prop = std.math.maxInt(u16); | ||
| 165 | \\ | ||
| 152 | \\inline fn getProp(cp: u21) Prop { | 166 | \\inline fn getProp(cp: u21) Prop { |
| 153 | \\ const stage_1_index = cp >> 8; | 167 | \\ const stage_1_index = cp >> 8; |
| 168 | \\ if (stage_1[stage_1_index] == no_prop) return .none; | ||
| 154 | \\ const stage_2_index = stage_1[stage_1_index] + (cp & 0xff); | 169 | \\ const stage_2_index = stage_1[stage_1_index] + (cp & 0xff); |
| 155 | \\ const stage_3_index = stage_2[stage_2_index]; | 170 | \\ const stage_3_index = stage_2[stage_2_index]; |
| 156 | \\ return stage_3[stage_3_index]; | 171 | \\ return stage_3[stage_3_index]; |
diff --git a/src/main.zig b/src/main.zig index 43614cc..ca167e8 100644 --- a/src/main.zig +++ b/src/main.zig | |||
| @@ -1,7 +1,7 @@ | |||
| 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.zig").GraphemeIterator; | 4 | const GraphemeIterator = @import("Grapheme.zig").GraphemeIterator; |
| 5 | 5 | ||
| 6 | pub fn main() !void { | 6 | pub fn main() !void { |
| 7 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | 7 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |