summaryrefslogtreecommitdiff
path: root/src/WidthData.zig
diff options
context:
space:
mode:
authorGravatar Jose Colon2024-10-20 12:09:34 +0000
committerGravatar Jose Colon2024-10-20 12:09:34 +0000
commit70d17ea7aab18178a5f5ffa120229151a8f943e6 (patch)
tree07ab43f86fa96c93c275b4b90d685a9ef31d3865 /src/WidthData.zig
parentFixed benchmark duration printing (diff)
parentWidthData: define error set as mem.Allocator.Error (diff)
downloadzg-70d17ea7aab18178a5f5ffa120229151a8f943e6.tar.gz
zg-70d17ea7aab18178a5f5ffa120229151a8f943e6.tar.xz
zg-70d17ea7aab18178a5f5ffa120229151a8f943e6.zip
Merge pull request 'GraphemeData and WidthData: make init read errors unreachable and define return errorset' (#16) from rockorager/zg:master into master
Reviewed-on: https://codeberg.org/dude_the_builder/zg/pulls/16
Diffstat (limited to 'src/WidthData.zig')
-rw-r--r--src/WidthData.zig10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/WidthData.zig b/src/WidthData.zig
index 1f1ae6f..1b7fb2e 100644
--- a/src/WidthData.zig
+++ b/src/WidthData.zig
@@ -13,7 +13,7 @@ s2: []i3 = undefined,
13 13
14const Self = @This(); 14const Self = @This();
15 15
16pub fn init(allocator: mem.Allocator) !Self { 16pub fn init(allocator: mem.Allocator) mem.Allocator.Error!Self {
17 const decompressor = compress.flate.inflate.decompressor; 17 const decompressor = compress.flate.inflate.decompressor;
18 const in_bytes = @embedFile("dwp"); 18 const in_bytes = @embedFile("dwp");
19 var in_fbs = std.io.fixedBufferStream(in_bytes); 19 var in_fbs = std.io.fixedBufferStream(in_bytes);
@@ -28,15 +28,15 @@ pub fn init(allocator: mem.Allocator) !Self {
28 }; 28 };
29 errdefer self.g_data.deinit(); 29 errdefer self.g_data.deinit();
30 30
31 const stage_1_len: u16 = try reader.readInt(u16, endian); 31 const stage_1_len: u16 = reader.readInt(u16, endian) catch unreachable;
32 self.s1 = try allocator.alloc(u16, stage_1_len); 32 self.s1 = try allocator.alloc(u16, stage_1_len);
33 errdefer allocator.free(self.s1); 33 errdefer allocator.free(self.s1);
34 for (0..stage_1_len) |i| self.s1[i] = try reader.readInt(u16, endian); 34 for (0..stage_1_len) |i| self.s1[i] = reader.readInt(u16, endian) catch unreachable;
35 35
36 const stage_2_len: u16 = try reader.readInt(u16, endian); 36 const stage_2_len: u16 = reader.readInt(u16, endian) catch unreachable;
37 self.s2 = try allocator.alloc(i3, stage_2_len); 37 self.s2 = try allocator.alloc(i3, stage_2_len);
38 errdefer allocator.free(self.s2); 38 errdefer allocator.free(self.s2);
39 for (0..stage_2_len) |i| self.s2[i] = @intCast(try reader.readInt(i8, endian)); 39 for (0..stage_2_len) |i| self.s2[i] = @intCast(reader.readInt(i8, endian) catch unreachable);
40 40
41 return self; 41 return self;
42} 42}