replaced TomlArray with tlibc List
This commit is contained in:
@@ -6,37 +6,15 @@
|
||||
|
||||
TomlArray* TomlArray_new(void)
|
||||
{
|
||||
TomlArray* array = malloc(sizeof(TomlArray));
|
||||
array->elements = NULL;
|
||||
array->len = 0;
|
||||
array->_capacity = 0;
|
||||
TomlArray* array = (TomlArray*)malloc(sizeof(TomlArray));
|
||||
*array = List_TomlValue_construct(NULL, 0, 0);
|
||||
return array;
|
||||
}
|
||||
|
||||
void TomlArray_free(TomlArray* self)
|
||||
{
|
||||
if (self == NULL)
|
||||
if(!self)
|
||||
return;
|
||||
|
||||
for (u64 i = 0; i < self->len; i++) {
|
||||
TomlValue_destroy(&self->elements[i]);
|
||||
}
|
||||
free(self->elements);
|
||||
List_TomlValue_destroy(self);
|
||||
free(self);
|
||||
}
|
||||
|
||||
void TomlArray_expand_if_necessary(TomlArray* self)
|
||||
{
|
||||
if (self->len + 1 > self->_capacity) {
|
||||
u64 new_capacity = self->_capacity > 0 ? self->_capacity * 2 : 8;
|
||||
void* p = realloc(self->elements, sizeof(TomlValue) * new_capacity);
|
||||
self->elements = p;
|
||||
self->_capacity = new_capacity;
|
||||
}
|
||||
}
|
||||
|
||||
void TomlArray_append(TomlArray* self, TomlValue value)
|
||||
{
|
||||
TomlArray_expand_if_necessary(self);
|
||||
self->elements[self->len++] = value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user