From 460b4077e73da7bbfae4b8b341e9025cebc02c50 Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Thu, 1 May 2025 21:45:59 -0400 Subject: Remove inner setup from GeneralCategories It was one `try` block away from only returning Allocator.Error, so now there's no need to filter errors in an outer `catch`. --- README.md | 2 +- src/GeneralCategories.zig | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 56592ce..5b471b5 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ test "Code point iterator" { ## Grapheme Clusters Many characters are composed from more than one code point. These are known as -Grapheme Clusters and the `grapheme` module has a data structure to represent +Grapheme Clusters, and the `Graphemes` module has a data structure to represent them, `Grapheme`, and an `Iterator` to iterate over them in a string. In your `build.zig`: diff --git a/src/GeneralCategories.zig b/src/GeneralCategories.zig index 3e76d82..8c1b6a3 100644 --- a/src/GeneralCategories.zig +++ b/src/GeneralCategories.zig @@ -47,15 +47,6 @@ pub fn init(allocator: Allocator) Allocator.Error!GeneralCategories { } pub fn setup(gencat: *GeneralCategories, allocator: Allocator) Allocator.Error!void { - gencat.setupInner(allocator) catch |err| { - switch (err) { - error.OutOfMemory => |e| return e, - else => unreachable, - } - }; -} - -inline fn setupInner(gencat: *GeneralCategories, allocator: Allocator) !void { const decompressor = compress.flate.inflate.decompressor; const in_bytes = @embedFile("gencat"); var in_fbs = std.io.fixedBufferStream(in_bytes); @@ -67,7 +58,7 @@ inline fn setupInner(gencat: *GeneralCategories, allocator: Allocator) !void { const s1_len: u16 = reader.readInt(u16, endian) catch unreachable; gencat.s1 = try allocator.alloc(u16, s1_len); errdefer allocator.free(gencat.s1); - for (0..s1_len) |i| gencat.s1[i] = try reader.readInt(u16, endian); + for (0..s1_len) |i| gencat.s1[i] = reader.readInt(u16, endian) catch unreachable; const s2_len: u16 = reader.readInt(u16, endian) catch unreachable; gencat.s2 = try allocator.alloc(u5, s2_len); -- cgit v1.2.3