summaryrefslogtreecommitdiff
path: root/src/CanonData.zig
diff options
context:
space:
mode:
authorGravatar lch3612025-03-25 00:29:52 +0300
committerGravatar Sam Atman2025-04-29 12:30:55 -0400
commit2f44fdebca57d9eabb682e05d04189d0600b8664 (patch)
tree617e7d4be89c1a965848dbc7f9b5f2a273faa9d7 /src/CanonData.zig
parentBump copyright year, isolate iterator tests (diff)
downloadzg-2f44fdebca57d9eabb682e05d04189d0600b8664.tar.gz
zg-2f44fdebca57d9eabb682e05d04189d0600b8664.tar.xz
zg-2f44fdebca57d9eabb682e05d04189d0600b8664.zip
All the std.mem.Allocators that were stored just for init and deinit
methods were removed, mem.Allocators were added to deinit as arguments.
Diffstat (limited to 'src/CanonData.zig')
-rw-r--r--src/CanonData.zig22
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");
3const compress = std.compress; 3const compress = std.compress;
4const mem = std.mem; 4const mem = std.mem;
5 5
6allocator: mem.Allocator, 6nfc: std.AutoHashMapUnmanaged([2]u21, u21),
7nfc: std.AutoHashMap([2]u21, u21),
8nfd: [][]u21 = undefined, 7nfd: [][]u21 = undefined,
9 8
10const Self = @This(); 9const 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
52pub fn deinit(self: *Self) void { 50pub 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`.