From 2f44fdebca57d9eabb682e05d04189d0600b8664 Mon Sep 17 00:00:00 2001 From: lch361 Date: Tue, 25 Mar 2025 00:29:52 +0300 Subject: All the std.mem.Allocators that were stored just for init and deinit methods were removed, mem.Allocators were added to deinit as arguments. --- src/CanonData.zig | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/CanonData.zig') 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"); const compress = std.compress; const mem = std.mem; -allocator: mem.Allocator, -nfc: std.AutoHashMap([2]u21, u21), +nfc: std.AutoHashMapUnmanaged([2]u21, u21), nfd: [][]u21 = undefined, const Self = @This(); @@ -18,16 +17,15 @@ pub fn init(allocator: mem.Allocator) !Self { const endian = builtin.cpu.arch.endian(); var self = Self{ - .allocator = allocator, - .nfc = std.AutoHashMap([2]u21, u21).init(allocator), + .nfc = .{}, .nfd = try allocator.alloc([]u21, 0x110000), }; var slices: usize = 0; errdefer { - self.nfc.deinit(); - for (self.nfd[0..slices]) |slice| self.allocator.free(slice); - self.allocator.free(self.nfd); + self.nfc.deinit(allocator); + for (self.nfd[0..slices]) |slice| allocator.free(slice); + allocator.free(self.nfd); } @memset(self.nfd, &.{}); @@ -42,17 +40,17 @@ pub fn init(allocator: mem.Allocator) !Self { self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian)); } if (len == 3) { - try self.nfc.put(self.nfd[cp][0..2].*, @intCast(cp)); + try self.nfc.put(allocator, self.nfd[cp][0..2].*, @intCast(cp)); } } return self; } -pub fn deinit(self: *Self) void { - self.nfc.deinit(); - for (self.nfd) |slice| self.allocator.free(slice); - self.allocator.free(self.nfd); +pub fn deinit(self: *Self, allocator: mem.Allocator) void { + self.nfc.deinit(allocator); + for (self.nfd) |slice| allocator.free(slice); + allocator.free(self.nfd); } /// Returns canonical decomposition for `cp`. -- cgit v1.2.3