fix: dont copy unset map nodes
This commit is contained in:
19
map.c
19
map.c
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user