Fix missing free on GrowableBitSet. init_new/init_temp for GrowableBitSet, LinkedList, List, HashMap, DString, ByteBuffer. Interface to_string renamed to_new_string. Change in allocator usage, malloc is now heap. Added new_array, new_zero_array, new, new_clear, clone. Concat => concat_new. string::printf => string::new_format, string::tprintf => string::tformat. "to_*" are now "to_new_*" and "to_temp_*". "from_*" is "new_from*"

This commit is contained in:
Christoffer Lerno
2023-11-06 23:20:41 +01:00
committed by Christoffer Lerno
parent 69470b8738
commit 1e38ccdd2b
77 changed files with 1049 additions and 1412 deletions

View File

@@ -28,12 +28,20 @@ fn void LinkedList.push_last(&self, Type value)
self.link_last(value);
}
fn void LinkedList.init(&self, Allocator* using = mem::heap())
/**
* @param [&inout] allocator "The allocator to use, defaults to the heap allocator"
* @return "the initialized list"
**/
fn LinkedList* LinkedList.init_new(&self, Allocator* allocator = mem::heap())
{
*self = { .allocator = using };
*self = { .allocator = allocator };
return self;
}
fn void LinkedList.tinit(&self) => self.init(mem::temp()) @inline;
fn LinkedList* LinkedList.init_temp(&self)
{
return self.init_new(mem::temp()) @inline;
}
/**
* @require self.allocator
@@ -45,7 +53,7 @@ macro void LinkedList.free_node(&self, Node* node) @private
macro Node* LinkedList.alloc_node(&self) @private
{
if (!self.allocator) self.allocator = mem::heap();
return malloc(Node, .using = self.allocator);
return self.allocator.new(Node);
}
fn void LinkedList.link_first(&self, Type value) @private
@@ -175,7 +183,7 @@ fn void LinkedList.insert(&self, usz index, Type element)
fn void LinkedList.link_before(&self, Node *succ, Type value) @private
{
Node* pred = succ.prev;
Node* new_node = malloc(Node);
Node* new_node = self.alloc_node();
*new_node = { .prev = pred, .next = succ, .value = value };
succ.prev = new_node;
if (!pred)