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/ScriptsData.zig | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/ScriptsData.zig') diff --git a/src/ScriptsData.zig b/src/ScriptsData.zig index 415ce2d..4ad8549 100644 --- a/src/ScriptsData.zig +++ b/src/ScriptsData.zig @@ -172,7 +172,6 @@ pub const Script = enum { Zanabazar_Square, }; -allocator: mem.Allocator, s1: []u16 = undefined, s2: []u8 = undefined, s3: []u8 = undefined, @@ -188,7 +187,7 @@ pub fn init(allocator: mem.Allocator) !Self { const endian = builtin.cpu.arch.endian(); - var self = Self{ .allocator = allocator }; + var self = Self{}; const s1_len: u16 = try reader.readInt(u16, endian); self.s1 = try allocator.alloc(u16, s1_len); @@ -208,10 +207,10 @@ pub fn init(allocator: mem.Allocator) !Self { return self; } -pub fn deinit(self: *const Self) void { - self.allocator.free(self.s1); - self.allocator.free(self.s2); - self.allocator.free(self.s3); +pub fn deinit(self: *const Self, allocator: mem.Allocator) void { + allocator.free(self.s1); + allocator.free(self.s2); + allocator.free(self.s3); } /// Lookup the Script type for `cp`. @@ -223,6 +222,6 @@ pub fn script(self: Self, cp: u21) ?Script { test "script" { const self = try init(std.testing.allocator); - defer self.deinit(); + defer self.deinit(std.testing.allocator); try testing.expectEqual(Script.Latin, self.script('A').?); } -- cgit v1.2.3