fix: dont copy unset map nodes

This commit is contained in:
2023-12-08 04:24:47 +01:00
parent b203c93f47
commit a76c093c9f
3 changed files with 13 additions and 12 deletions

19
map.c
View File

@@ -19,7 +19,7 @@ typedef struct MapNode_struct {
int value;
} MapNode;
struct _Map {
struct Map_struct {
MapNode *nodes;
uint32_t size;
uint32_t capacity;
@@ -126,15 +126,16 @@ __inline void map_ensure_capacity(Map *map) {
for(int i = 0; i < capacity; i++) {
MapNode node = nodes[i];
MapNode *next = node.next;
if(next == NULL) {
continue;
}
map_set_node(map, node);
if(next != NULL) {
while((size_t) next != UINTPTR_MAX) {
map_set_node(map, *next);
MapNode *after = next->next;
assert(after != NULL);
free(next);
next = after;
}
while((size_t) next != UINTPTR_MAX) {
map_set_node(map, *next);
MapNode *after = next->next;
assert(after != NULL);
free(next);
next = after;
}
}
free(nodes);