From 312ca415bb01212a320acacda743896ed59a7b82 Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Wed, 30 Apr 2025 15:23:14 -0400 Subject: Remove FoldData, make CaseFolding CaseFolding now has the FoldData, and can be initialized with a copy of Normalize if wanted. --- src/CanonData.zig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/CanonData.zig') diff --git a/src/CanonData.zig b/src/CanonData.zig index c67d1d6..d95a5be 100644 --- a/src/CanonData.zig +++ b/src/CanonData.zig @@ -17,11 +17,11 @@ pub fn init(allocator: mem.Allocator) !CanonData { .nfc = .empty, .nfd = try allocator.alloc([]u21, 0x110000), }; + var _cp: u24 = undefined; - var slices: usize = 0; errdefer { cdata.nfc.deinit(allocator); - for (cdata.nfd[0..slices]) |slice| allocator.free(slice); + for (cdata.nfd[0.._cp]) |slice| allocator.free(slice); allocator.free(cdata.nfd); } @@ -31,14 +31,16 @@ pub fn init(allocator: mem.Allocator) !CanonData { const len: u8 = try reader.readInt(u8, endian); if (len == 0) break; const cp = try reader.readInt(u24, endian); - cdata.nfd[cp] = try allocator.alloc(u21, len - 1); - slices += 1; + _cp = cp; + const nfd_cp = try allocator.alloc(u21, len - 1); + errdefer allocator.free(nfd_cp); for (0..len - 1) |i| { - cdata.nfd[cp][i] = @intCast(try reader.readInt(u24, endian)); + nfd_cp[i] = @intCast(try reader.readInt(u24, endian)); } if (len == 3) { - try cdata.nfc.put(allocator, cdata.nfd[cp][0..2].*, @intCast(cp)); + try cdata.nfc.put(allocator, nfd_cp[0..2].*, @intCast(cp)); } + cdata.nfd[cp] = nfd_cp; } return cdata; -- cgit v1.2.3