invert if-condition in preparation for the next bugfix

Fri, 12 Aug 2022 16:48:59 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 12 Aug 2022 16:48:59 +0200
changeset 574
d566bd3e6af8
parent 573
3f3a0d19db58
child 575
b05935945637

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;

mercurial