diff --git a/src/sections.zig b/src/sections.zig index eb59819..3a3d55a 100644 --- a/src/sections.zig +++ b/src/sections.zig @@ -3,6 +3,7 @@ const fmt = std.fmt; const mem = std.mem; const math = std.math; const sort = std.sort; +const assert = std.debug.assert; const unicode = std.unicode; const Allocator = std.mem.Allocator; const ArrayListUnmanaged = std.ArrayListUnmanaged; @@ -224,11 +225,11 @@ pub fn usersSection( errdefer blob.deinit(); var i: usize = 0; while (i < corpus.users.len) : (i += 1) { - // TODO: this is inefficient; it's calling `.slice()` on every iteration + // TODO: this is inefficient by calling `.slice()` on every iteration const user = corpus.users.get(i); - const user_offset = try math.cast(u32, blob.items.len); - std.debug.assert(user_offset & 7 == 0); - idx2offset[i] = user_offset; + const user_offset = try math.cast(u35, blob.items.len); + assert(user_offset & 7 == 0); + idx2offset[i] = @truncate(u32, user_offset >> 3); try userImport.PackedUser.packTo( &blob, user, @@ -324,7 +325,7 @@ pub fn groupsSection( // TODO: this is inefficient; it's calling `.slice()` on every iteration const group = corpus.groups.get(i); const group_offset = try math.cast(u32, blob.items.len); - std.debug.assert(group_offset & 7 == 0); + assert(group_offset & 7 == 0); idx2offset[i] = group_offset; const group_stored = groupImport.GroupStored{ .gid = group.gid, @@ -355,7 +356,7 @@ pub fn bdzIdx( else => unreachable, } }; - std.debug.assert(keys.len <= math.maxInt(u32)); + assert(keys.len <= math.maxInt(u32)); var result = try allocator.alloc(u32, keys.len); for (keys) |key, i| { const hash = search_fn(packed_mphf, key); diff --git a/src/shell.zig b/src/shell.zig index ecdc116..ec1c09e 100644 --- a/src/shell.zig +++ b/src/shell.zig @@ -79,6 +79,7 @@ pub const ShellWriter = struct { try self.blob.appendSlice(shells.get(idx)); const our_shell = self.blob.constSlice()[full_offset .. full_offset + len]; try self.indices.put(our_shell, idx); + std.debug.assert(full_offset & 3 == 0); self.index.set(idx, ShellIndex{ .offset = try std.math.cast(u10, full_offset >> 2), .len = len - 1,