authorgravatar for contact@fengb.meBenjamin Feng <contact@fengb.me> 2019-12-03 23:49:56-06:00
committergravatar for contact@fengb.meBenjamin Feng <contact@fengb.me> 2019-12-04 00:08:09-06:00
log01e73bba8d8c98558de35a43e82a5f8de837d8a5
tree2f4842f017860166f9660e1c872ea48426d3de1b
parentbaffaf7986d34b47580819eb70b66a5311556046

Tighten recycled search


1 files changed, 9 insertions(+), 18 deletions(-)

lib/std/heap.zig+9-18
......@@ -280,9 +280,7 @@ const WasmPageAllocator = struct {
280280 }
281281
282282 fn useRecycled(self: *FreeBlock, num_pages: usize) ?[*]u8 {
283 var found_idx: usize = 0;
284 var found_size: usize = 0;
285
283 @setCold(true);
286284 for (self.block_data) |segment, i| {
287285 const spills_into_next = @bitCast(i128, segment) < 0;
288286 const has_enough_bits = @popCount(u128, segment) >= num_pages;
......@@ -290,23 +288,16 @@ const WasmPageAllocator = struct {
290288 if (!spills_into_next and !has_enough_bits) continue;
291289
292290 var j: usize = i * 128;
293 while (j < self.packed_data.int_count) : (j += 1) {
294 if (self.packed_data.get(j) == 0) {
295 found_size = 0;
296 if (j > (i + 1) * 128) {
297 break;
298 }
299 } else {
300 if (found_size == 0) {
301 found_idx = j;
302 }
303 found_size += 1;
304
305 if (found_size >= num_pages) {
306 self.setBits(found_idx, found_size, 0);
307 return @intToPtr([*]u8, (found_idx + self.offset) * std.mem.page_size);
291 while (j < (i + 1) * 128) : (j += 1) {
292 var count: usize = 0;
293 while (j + count < self.packed_data.int_count and self.packed_data.get(j + count) == 1) {
294 count += 1;
295 if (count >= num_pages) {
296 self.setBits(j, num_pages, 0);
297 return @intToPtr([*]u8, (j + self.offset) * std.mem.page_size);
308298 }
309299 }
300 j += count;
310301 }
311302 }
312303 return null;