|
|
|
@@ -476,12 +476,14 @@ typedef struct {
|
|
|
|
|
static ElList* list_alloc(int64_t cap) {
|
|
|
|
|
if (cap < 4) cap = 4;
|
|
|
|
|
ElList* lst = malloc(sizeof(ElList));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += sizeof(ElList);
|
|
|
|
|
if (!lst) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
lst->hdr.magic = EL_MAGIC_LIST;
|
|
|
|
|
lst->hdr.refcount = 1;
|
|
|
|
|
lst->length = 0;
|
|
|
|
|
lst->capacity = cap;
|
|
|
|
|
lst->elems = malloc((size_t)cap * sizeof(el_val_t));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += (size_t)cap * sizeof(el_val_t);
|
|
|
|
|
if (!lst->elems) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
return lst;
|
|
|
|
|
}
|
|
|
|
@@ -531,6 +533,7 @@ el_val_t el_list_append(el_val_t listv, el_val_t elem) {
|
|
|
|
|
if (old->length >= old->capacity) {
|
|
|
|
|
int64_t new_cap = old->capacity > 0 ? old->capacity * 2 : 4;
|
|
|
|
|
el_val_t* grown = realloc(old->elems, (size_t)new_cap * sizeof(el_val_t));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += (size_t)new_cap * sizeof(el_val_t);
|
|
|
|
|
if (!grown) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
old->elems = grown;
|
|
|
|
|
old->capacity = new_cap;
|
|
|
|
@@ -543,12 +546,14 @@ el_val_t el_list_append(el_val_t listv, el_val_t elem) {
|
|
|
|
|
int64_t new_cap = old->length + 1;
|
|
|
|
|
if (new_cap < 4) new_cap = 4;
|
|
|
|
|
ElList* fresh = malloc(sizeof(ElList));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += sizeof(ElList);
|
|
|
|
|
if (!fresh) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
fresh->hdr.magic = EL_MAGIC_LIST;
|
|
|
|
|
fresh->hdr.refcount = 1;
|
|
|
|
|
fresh->length = old->length + 1;
|
|
|
|
|
fresh->capacity = new_cap;
|
|
|
|
|
fresh->elems = malloc((size_t)new_cap * sizeof(el_val_t));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += (size_t)new_cap * sizeof(el_val_t);
|
|
|
|
|
if (!fresh->elems) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
if (old->length > 0) {
|
|
|
|
|
memcpy(fresh->elems, old->elems, (size_t)old->length * sizeof(el_val_t));
|
|
|
|
@@ -570,12 +575,14 @@ el_val_t el_list_clone(el_val_t listv) {
|
|
|
|
|
if (cap < old->length) cap = old->length;
|
|
|
|
|
if (cap < 4) cap = 4;
|
|
|
|
|
ElList* fresh = malloc(sizeof(ElList));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += sizeof(ElList);
|
|
|
|
|
if (!fresh) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
fresh->hdr.magic = EL_MAGIC_LIST;
|
|
|
|
|
fresh->hdr.refcount = 1;
|
|
|
|
|
fresh->length = old->length;
|
|
|
|
|
fresh->capacity = cap;
|
|
|
|
|
fresh->elems = malloc((size_t)cap * sizeof(el_val_t));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += (size_t)cap * sizeof(el_val_t);
|
|
|
|
|
if (!fresh->elems) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
if (old->length > 0) {
|
|
|
|
|
memcpy(fresh->elems, old->elems, (size_t)old->length * sizeof(el_val_t));
|
|
|
|
@@ -596,6 +603,7 @@ typedef struct {
|
|
|
|
|
static ElMap* map_alloc(int64_t cap) {
|
|
|
|
|
if (cap < 4) cap = 4;
|
|
|
|
|
ElMap* m = malloc(sizeof(ElMap));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += sizeof(ElMap);
|
|
|
|
|
if (!m) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
m->hdr.magic = EL_MAGIC_MAP;
|
|
|
|
|
m->hdr.refcount = 1;
|
|
|
|
@@ -671,6 +679,7 @@ el_val_t el_map_set(el_val_t mapv, el_val_t keyv, el_val_t value) {
|
|
|
|
|
int64_t new_cap = m->count + 1;
|
|
|
|
|
if (new_cap < 4) new_cap = 4;
|
|
|
|
|
ElMap* fresh = malloc(sizeof(ElMap));
|
|
|
|
|
_el_alloc_count++; _el_alloc_bytes += sizeof(ElMap);
|
|
|
|
|
if (!fresh) { fputs("el_runtime: out of memory\n", stderr); exit(1); }
|
|
|
|
|
fresh->hdr.magic = EL_MAGIC_MAP;
|
|
|
|
|
fresh->hdr.refcount = 1;
|
|
|
|
|