diff options
Diffstat (limited to 'src/CanonData.zig')
| -rw-r--r-- | src/CanonData.zig | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/src/CanonData.zig b/src/CanonData.zig index 05b9017..794748c 100644 --- a/src/CanonData.zig +++ b/src/CanonData.zig | |||
| @@ -3,8 +3,7 @@ const builtin = @import("builtin"); | |||
| 3 | const compress = std.compress; | 3 | const compress = std.compress; |
| 4 | const mem = std.mem; | 4 | const mem = std.mem; |
| 5 | 5 | ||
| 6 | allocator: mem.Allocator, | 6 | nfc: std.AutoHashMapUnmanaged([2]u21, u21), |
| 7 | nfc: std.AutoHashMap([2]u21, u21), | ||
| 8 | nfd: [][]u21 = undefined, | 7 | nfd: [][]u21 = undefined, |
| 9 | 8 | ||
| 10 | const Self = @This(); | 9 | const Self = @This(); |
| @@ -18,16 +17,15 @@ pub fn init(allocator: mem.Allocator) !Self { | |||
| 18 | 17 | ||
| 19 | const endian = builtin.cpu.arch.endian(); | 18 | const endian = builtin.cpu.arch.endian(); |
| 20 | var self = Self{ | 19 | var self = Self{ |
| 21 | .allocator = allocator, | 20 | .nfc = .{}, |
| 22 | .nfc = std.AutoHashMap([2]u21, u21).init(allocator), | ||
| 23 | .nfd = try allocator.alloc([]u21, 0x110000), | 21 | .nfd = try allocator.alloc([]u21, 0x110000), |
| 24 | }; | 22 | }; |
| 25 | 23 | ||
| 26 | var slices: usize = 0; | 24 | var slices: usize = 0; |
| 27 | errdefer { | 25 | errdefer { |
| 28 | self.nfc.deinit(); | 26 | self.nfc.deinit(allocator); |
| 29 | for (self.nfd[0..slices]) |slice| self.allocator.free(slice); | 27 | for (self.nfd[0..slices]) |slice| allocator.free(slice); |
| 30 | self.allocator.free(self.nfd); | 28 | allocator.free(self.nfd); |
| 31 | } | 29 | } |
| 32 | 30 | ||
| 33 | @memset(self.nfd, &.{}); | 31 | @memset(self.nfd, &.{}); |
| @@ -42,17 +40,17 @@ pub fn init(allocator: mem.Allocator) !Self { | |||
| 42 | self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian)); | 40 | self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian)); |
| 43 | } | 41 | } |
| 44 | if (len == 3) { | 42 | if (len == 3) { |
| 45 | try self.nfc.put(self.nfd[cp][0..2].*, @intCast(cp)); | 43 | try self.nfc.put(allocator, self.nfd[cp][0..2].*, @intCast(cp)); |
| 46 | } | 44 | } |
| 47 | } | 45 | } |
| 48 | 46 | ||
| 49 | return self; | 47 | return self; |
| 50 | } | 48 | } |
| 51 | 49 | ||
| 52 | pub fn deinit(self: *Self) void { | 50 | pub fn deinit(self: *Self, allocator: mem.Allocator) void { |
| 53 | self.nfc.deinit(); | 51 | self.nfc.deinit(allocator); |
| 54 | for (self.nfd) |slice| self.allocator.free(slice); | 52 | for (self.nfd) |slice| allocator.free(slice); |
| 55 | self.allocator.free(self.nfd); | 53 | allocator.free(self.nfd); |
| 56 | } | 54 | } |
| 57 | 55 | ||
| 58 | /// Returns canonical decomposition for `cp`. | 56 | /// Returns canonical decomposition for `cp`. |