diff options
Diffstat (limited to 'src/ArenaAllocator.zig')
-rw-r--r-- | src/ArenaAllocator.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/ArenaAllocator.zig b/src/ArenaAllocator.zig index 31e0cf5b9..999ea4142 100644 --- a/src/ArenaAllocator.zig +++ b/src/ArenaAllocator.zig @@ -111,7 +111,7 @@ pub const ArenaAllocator = struct { // value. const requested_capacity = switch (mode) { .retain_capacity => self.queryCapacity(), - .retain_with_limit => |limit| std.math.min(limit, self.queryCapacity()), + .retain_with_limit => |limit| @min(limit, self.queryCapacity()), .free_all => 0, }; if (requested_capacity == 0) { @@ -186,8 +186,8 @@ pub const ArenaAllocator = struct { while (true) { const cur_alloc_buf = @ptrCast([*]u8, cur_node)[0..cur_node.data]; const cur_buf = cur_alloc_buf[@sizeOf(BufNode)..]; - const addr = @ptrToInt(cur_buf.ptr) + self.state.end_index; - const adjusted_addr = mem.alignForward(addr, ptr_align); + const addr = @intFromPtr(cur_buf.ptr) + self.state.end_index; + const adjusted_addr = mem.alignForward(usize, addr, ptr_align); const adjusted_index = self.state.end_index + (adjusted_addr - addr); const new_end_index = adjusted_index + n; @@ -215,7 +215,7 @@ pub const ArenaAllocator = struct { const cur_node = self.state.buffer_list.first orelse return false; const cur_buf = @ptrCast([*]u8, cur_node)[@sizeOf(BufNode)..cur_node.data]; - if (@ptrToInt(cur_buf.ptr) + self.state.end_index != @ptrToInt(buf.ptr) + buf.len) { + if (@intFromPtr(cur_buf.ptr) + self.state.end_index != @intFromPtr(buf.ptr) + buf.len) { // It's not the most recent allocation, so it cannot be expanded, // but it's fine if they want to make it smaller. return new_len <= buf.len; @@ -241,7 +241,7 @@ pub const ArenaAllocator = struct { const cur_node = self.state.buffer_list.first orelse return; const cur_buf = @ptrCast([*]u8, cur_node)[@sizeOf(BufNode)..cur_node.data]; - if (@ptrToInt(cur_buf.ptr) + self.state.end_index == @ptrToInt(buf.ptr) + buf.len) { + if (@intFromPtr(cur_buf.ptr) + self.state.end_index == @intFromPtr(buf.ptr) + buf.len) { self.state.end_index -= buf.len; } } @@ -263,7 +263,7 @@ test "ArenaAllocator (reset with preheating)" { const size = random.intRangeAtMost(usize, 16, 256); const alignment = 32; const slice = try arena_allocator.allocator().alignedAlloc(u8, alignment, size); - try std.testing.expect(std.mem.isAligned(@ptrToInt(slice.ptr), alignment)); + try std.testing.expect(std.mem.isAligned(@intFromPtr(slice.ptr), alignment)); try std.testing.expectEqual(size, slice.len); alloced_bytes += slice.len; } |