Skip to content

Commit 09546e7

Browse files
SeanTheGleamingVexu
authored andcommitted
Update arena_allocator.zig
Rework some pointer arithmetic, reduce usage of `@intFromPtr`
1 parent 2c611b5 commit 09546e7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/std/heap/arena_allocator.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub const ArenaAllocator = struct {
214214

215215
const cur_node = self.state.buffer_list.first orelse return false;
216216
const cur_buf = @as([*]u8, @ptrCast(cur_node))[@sizeOf(BufNode)..cur_node.data];
217-
if (@intFromPtr(cur_buf.ptr) + self.state.end_index != @intFromPtr(buf.ptr) + buf.len) {
217+
if (cur_buf.ptr + self.state.end_index != buf.ptr + buf.len) {
218218
// It's not the most recent allocation, so it cannot be expanded,
219219
// but it's fine if they want to make it smaller.
220220
return new_len <= buf.len;
@@ -240,7 +240,7 @@ pub const ArenaAllocator = struct {
240240
const cur_node = self.state.buffer_list.first orelse return;
241241
const cur_buf = @as([*]u8, @ptrCast(cur_node))[@sizeOf(BufNode)..cur_node.data];
242242

243-
if (@intFromPtr(cur_buf.ptr) + self.state.end_index == @intFromPtr(buf.ptr) + buf.len) {
243+
if (cur_buf.ptr + self.state.end_index == buf.ptr + buf.len) {
244244
self.state.end_index -= buf.len;
245245
}
246246
}

0 commit comments

Comments
 (0)