| ... | @@ -280,9 +280,7 @@ const WasmPageAllocator = struct { | ... | @@ -280,9 +280,7 @@ const WasmPageAllocator = struct { |
| 280 | } | 280 | } |
| 281 | | 281 | |
| 282 | fn useRecycled(self: *FreeBlock, num_pages: usize) ?[*]u8 { | 282 | fn useRecycled(self: *FreeBlock, num_pages: usize) ?[*]u8 { |
| 283 | var found_idx: usize = 0; | 283 | @setCold(true); |
| 284 | var found_size: usize = 0; | | |
| 285 | | | |
| 286 | for (self.block_data) |segment, i| { | 284 | for (self.block_data) |segment, i| { |
| 287 | const spills_into_next = @bitCast(i128, segment) < 0; | 285 | const spills_into_next = @bitCast(i128, segment) < 0; |
| 288 | const has_enough_bits = @popCount(u128, segment) >= num_pages; | 286 | const has_enough_bits = @popCount(u128, segment) >= num_pages; |
| ... | @@ -290,23 +288,16 @@ const WasmPageAllocator = struct { | ... | @@ -290,23 +288,16 @@ const WasmPageAllocator = struct { |
| 290 | if (!spills_into_next and !has_enough_bits) continue; | 288 | if (!spills_into_next and !has_enough_bits) continue; |
| 291 | | 289 | |
| 292 | var j: usize = i * 128; | 290 | var j: usize = i * 128; |
| 293 | while (j < self.packed_data.int_count) : (j += 1) { | 291 | while (j < (i + 1) * 128) : (j += 1) { |
| 294 | if (self.packed_data.get(j) == 0) { | 292 | var count: usize = 0; |
| 295 | found_size = 0; | 293 | while (j + count < self.packed_data.int_count and self.packed_data.get(j + count) == 1) { |
| 296 | if (j > (i + 1) * 128) { | 294 | count += 1; |
| 297 | break; | 295 | if (count >= num_pages) { |
| 298 | } | 296 | self.setBits(j, num_pages, 0); |
| 299 | } else { | 297 | return @intToPtr([*]u8, (j + self.offset) * std.mem.page_size); |
| 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); | | |
| 308 | } | 298 | } |
| 309 | } | 299 | } |
| | 300 | j += count; |
| 310 | } | 301 | } |
| 311 | } | 302 | } |
| 312 | return null; | 303 | return null; |