1
Fork 0

multi_array_list: use slice() when possible

This commit is contained in:
Motiejus Jakštys 2023-05-19 16:12:33 +03:00
parent 82ab622c66
commit 6d957967ed
2 changed files with 10 additions and 10 deletions

View File

@ -580,9 +580,10 @@ fn usersSection(
// 8 bytes. 24 is an optimistic lower bound for an average record size.
var blob = try ArrayListAligned(u8, 8).initCapacity(allocator, 24 * corpus.users.len);
errdefer blob.deinit();
for (0..corpus.users.len) |i| {
const users = corpus.users.slice();
for (0..users.len) |i| {
// TODO: this may be inefficient by calling `.slice()` on every iteration?
const user = corpus.users.get(i);
const user = users.get(i);
const user_offset = math.cast(u35, blob.items.len) orelse return error.TooMany;
assert(user_offset & 7 == 0);
idx2offset[i] = @truncate(u32, user_offset >> 3);
@ -595,7 +596,7 @@ fn usersSection(
try blob.appendNTimes(0, mem.alignForward(blob.items.len, 8) - blob.items.len);
}
return UsersSection{
.len = @intCast(u32, corpus.users.len),
.len = @intCast(u32, users.len),
.idx2offset = idx2offset,
.blob = try blob.toOwnedSlice(),
};

View File

@ -215,17 +215,16 @@ test "turbonss-unix2db smoke test" {
const group_fd = try os.open(groupPath, os.O.CREAT | os.O.WRONLY, 0o644);
var i: usize = 0;
while (i < corpus.users.len) : (i += 1) {
const user = corpus.users.get(i);
const line = user.toLine().constSlice();
_ = try os.write(passwd_fd, line);
}
const users = corpus.users.slice();
while (i < users.len) : (i += 1)
_ = try os.write(passwd_fd, users.get(i).toLine().constSlice());
os.close(passwd_fd);
var group_writer = (fs.File{ .handle = group_fd }).writer();
i = 0;
while (i < corpus.groups.len) : (i += 1)
try corpus.groups.get(i).writeTo(group_writer);
const groups = corpus.groups.slice();
while (i < groups.len) : (i += 1)
try groups.get(i).writeTo(group_writer);
os.close(group_fd);
const args = &[_][*:0]const u8{