diff options
| author | Benjamin Feng <contact@fengb.me> | 2019-12-03 23:49:56 -0600 |
|---|---|---|
| committer | Benjamin Feng <contact@fengb.me> | 2019-12-04 00:08:09 -0600 |
| commit | 01e73bba8d8c98558de35a43e82a5f8de837d8a5 (patch) | |
| tree | 2f4842f017860166f9660e1c872ea48426d3de1b /lib/std | |
| parent | baffaf7986d34b47580819eb70b66a5311556046 (diff) | |
| download | zig-01e73bba8d8c98558de35a43e82a5f8de837d8a5.tar.gz zig-01e73bba8d8c98558de35a43e82a5f8de837d8a5.zip | |
Tighten recycled search
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/heap.zig | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/lib/std/heap.zig b/lib/std/heap.zig index 8a2d7f0cf7..20f2b94766 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -280,9 +280,7 @@ const WasmPageAllocator = struct { } fn useRecycled(self: *FreeBlock, num_pages: usize) ?[*]u8 { - var found_idx: usize = 0; - var found_size: usize = 0; - + @setCold(true); for (self.block_data) |segment, i| { const spills_into_next = @bitCast(i128, segment) < 0; const has_enough_bits = @popCount(u128, segment) >= num_pages; @@ -290,23 +288,16 @@ const WasmPageAllocator = struct { if (!spills_into_next and !has_enough_bits) continue; var j: usize = i * 128; - while (j < self.packed_data.int_count) : (j += 1) { - if (self.packed_data.get(j) == 0) { - found_size = 0; - if (j > (i + 1) * 128) { - break; - } - } else { - if (found_size == 0) { - found_idx = j; - } - found_size += 1; - - if (found_size >= num_pages) { - self.setBits(found_idx, found_size, 0); - return @intToPtr([*]u8, (found_idx + self.offset) * std.mem.page_size); + while (j < (i + 1) * 128) : (j += 1) { + var count: usize = 0; + while (j + count < self.packed_data.int_count and self.packed_data.get(j + count) == 1) { + count += 1; + if (count >= num_pages) { + self.setBits(j, num_pages, 0); + return @intToPtr([*]u8, (j + self.offset) * std.mem.page_size); } } + j += count; } } return null; |
