From 2cdcdc167fdef50dbe003419305f40e4499622de Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Mon, 30 Sep 2024 12:08:31 +0200 Subject: [PATCH] better growth --- arena.h | 2 +- simap.h | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/arena.h b/arena.h index 70f97b8..3037bf6 160000 --- a/arena.h +++ b/arena.h @@ -1 +1 @@ -Subproject commit 70f97b8291454efbf9606051352c15ea6ebca319 +Subproject commit 3037bf6bec96b0ebc231510d308da1daece276fd diff --git a/simap.h b/simap.h index e90ea9e..47aa2fe 100644 --- a/simap.h +++ b/simap.h @@ -144,10 +144,16 @@ static inline uint32_t simap_elem_storage_size(const char *key) { /** Force-add the (key,value) to the end of the map */ static inline void *simap_force_add_internal(simap_instance *map, const char *key, void *ptr) { uint32_t storage_needed = simap_elem_storage_size(key); + assert((storage_needed & 8) == 0); if(map->end - map->usage_end > storage_needed) { /* Need storage */ - /* TODO: Implement */ - // Soemthin' like = ((T*) alloc(&a, sizeof(T), sizeof(T), 1)) + 1; + aralloc(&(map->a), + sizeof(uint8_t)/*esize*/, + 1 /*align - should be 8 but should be aligned here as-is! */, + storage_needed); + + /* Administer end offset */ + map->end += storage_needed; } /* Already have the storage */ @@ -191,9 +197,11 @@ static inline void* simap(void *amap_instance, AMAP_OP op, const char *key, void found->ptr = ptr; return (void *) found; } else { + return simap_force_add_internal(map, key, ptr); } } + assert(false); /* should be unreachable */ return NULL; }