replaced TomlArray with tlibc List

This commit is contained in:
2025-11-26 17:02:38 +05:00
parent 2082d56c25
commit 281a65f0d1
8 changed files with 89 additions and 114 deletions

View File

@@ -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;
}