authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-05-04 14:02:04+10:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-06-10 15:41:40+10:00
logb0648bfbd31cad73e00ee72b430dcf2c2907e08f
tree25a5a2da7a6527cf61096e236baf26c58d1ccc05
parentddf7942aaa6a41296d9338423dcdfb93b915e4df
signaturelock-open Commit is signed but in an unrecognized format.

std.heap.ArenaAllocator: use singly linked list


1 files changed, 5 insertions(+), 6 deletions(-)

std/heap.zig+5-6
...@@ -347,10 +347,10 @@ pub const ArenaAllocator = struct {...@@ -347,10 +347,10 @@ pub const ArenaAllocator = struct {
347 pub allocator: Allocator,347 pub allocator: Allocator,
348348
349 child_allocator: *Allocator,349 child_allocator: *Allocator,
350 buffer_list: std.TailQueue([]u8),350 buffer_list: std.SinglyLinkedList([]u8),
351 end_index: usize,351 end_index: usize,
352352
353 const BufNode = std.TailQueue([]u8).Node;353 const BufNode = std.SinglyLinkedList([]u8).Node;
354354
355 pub fn init(child_allocator: *Allocator) ArenaAllocator {355 pub fn init(child_allocator: *Allocator) ArenaAllocator {
356 return ArenaAllocator{356 return ArenaAllocator{
...@@ -359,7 +359,7 @@ pub const ArenaAllocator = struct {...@@ -359,7 +359,7 @@ pub const ArenaAllocator = struct {
359 .shrinkFn = shrink,359 .shrinkFn = shrink,
360 },360 },
361 .child_allocator = child_allocator,361 .child_allocator = child_allocator,
362 .buffer_list = std.TailQueue([]u8).init(),362 .buffer_list = std.SinglyLinkedList([]u8).init(),
363 .end_index = 0,363 .end_index = 0,
364 };364 };
365 }365 }
...@@ -387,10 +387,9 @@ pub const ArenaAllocator = struct {...@@ -387,10 +387,9 @@ pub const ArenaAllocator = struct {
387 const buf_node = &buf_node_slice[0];387 const buf_node = &buf_node_slice[0];
388 buf_node.* = BufNode{388 buf_node.* = BufNode{
389 .data = buf,389 .data = buf,
390 .prev = null,
391 .next = null,390 .next = null,
392 };391 };
393 self.buffer_list.append(buf_node);392 self.buffer_list.prepend(buf_node);
394 self.end_index = 0;393 self.end_index = 0;
395 return buf_node;394 return buf_node;
396 }395 }
...@@ -398,7 +397,7 @@ pub const ArenaAllocator = struct {...@@ -398,7 +397,7 @@ pub const ArenaAllocator = struct {
398 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {397 fn alloc(allocator: *Allocator, n: usize, alignment: u29) ![]u8 {
399 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);398 const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator);
400399
401 var cur_node = if (self.buffer_list.last) |last_node| last_node else try self.createNode(0, n + alignment);400 var cur_node = if (self.buffer_list.first) |first_node| first_node else try self.createNode(0, n + alignment);
402 while (true) {401 while (true) {
403 const cur_buf = cur_node.data[@sizeOf(BufNode)..];402 const cur_buf = cur_node.data[@sizeOf(BufNode)..];
404 const addr = @ptrToInt(cur_buf.ptr) + self.end_index;403 const addr = @ptrToInt(cur_buf.ptr) + self.end_index;