1
Fork 0

shr user and group offsets

by 3 bits, all of them.
main
Motiejus Jakštys 2022-03-15 10:48:56 +02:00 committed by Motiejus Jakštys
parent 249cdb1a31
commit 8a4bb62613
2 changed files with 8 additions and 6 deletions

View File

@ -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);

View File

@ -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,