Fri, 12 Aug 2022 16:48:59 +0200
invert if-condition in preparation for the next bugfix
src/hash_map.c | file | annotate | diff | comparison | revisions |
--- a/src/hash_map.c Fri Aug 12 16:47:11 2022 +0200 +++ b/src/hash_map.c Fri Aug 12 16:48:59 2022 +0200 @@ -86,7 +86,12 @@ elm = elm->next; } - if (elm == NULL || elm->key.hash != hash) { + if (elm != NULL && elm->key.hash == hash) { + // overwrite existing element + elm->data = value; + } else { + // insert new element + struct cx_hash_map_element_s *e = cxMalloc(allocator, sizeof(struct cx_hash_map_element_s)); if (e == NULL) { return -1; @@ -116,9 +121,6 @@ // increase the size map->size++; - } else { - // (elem != NULL && elem->key.hash == hash) - overwrite value of existing element - elm->data = value; } return 0;