1
Fork 0

scratch: free/alloc instead of realloc

that way the existing contents in scratch do not need to be copied over.
main
Motiejus Jakštys 2022-05-16 19:23:14 +03:00 committed by Motiejus Jakštys
parent 4f2c8707f4
commit 4cf7830f57
1 changed files with 8 additions and 2 deletions

View File

@ -400,14 +400,20 @@ fn additionalGids(
try compress.appendUvarint(&blob, 0);
var scratch = try allocator.alloc(u32, 256);
defer allocator.free(scratch);
var scratch_allocated: bool = true;
defer if (scratch_allocated) allocator.free(scratch);
for (corpus.user2groups) |usergroups, user_idx| {
if (usergroups.len == 0) {
idx2offset[user_idx] = 0;
continue;
}
idx2offset[user_idx] = blob.items.len;
scratch = try allocator.realloc(scratch, usergroups.len);
if (scratch.len < usergroups.len) {
allocator.free(scratch);
scratch_allocated = false;
scratch = try allocator.alloc(u32, usergroups.len);
scratch_allocated = true;
}
scratch.len = usergroups.len;
const corpusGids = corpus.groups.items(.gid);
for (usergroups) |group_idx, i|