shithub: mpl

Download patch

ref: e25befe3c61a7095acb09b9f097e9c7f2ddb7ad7
parent: 3ecd4002c0b2242d71d0af98e773c1ba5b9f97db
author: Moody <[email protected]>
date: Sat Apr 4 20:14:04 EDT 2020

Simplify mapinsert

--- a/dat.c
+++ b/dat.c
@@ -29,31 +29,31 @@
 void
 mapinsert(Hmap *h, char *key, void *val)
 {
-	Hnode *n, *end;
+	Hnode *n;
 
 	wlock(h);
 	n = h->nodes+(string2hash(key)%h->size);
 	assert(n != nil);
-	do {
+	for(;;){
 		if(n->key == nil)
-			goto new;
-		else if(strcmp(key, n->key) == 0)
+			goto empty;
+		if(strcmp(key, n->key) == 0)
 			goto found;
-		
-		end = n;
+		if(n->next == nil)
+			break;
 		n = n->next;
-	} while(n != nil);
-	n = end;
+	}
 
 	/* create new node */
 	n->next = emalloc(sizeof(Hnode));
 	n = n->next;
 
-new:
+empty:
 	n->key = strdup(key);
 
 found:
 	n->val = val;
+
 	wunlock(h);
 }
 
@@ -156,4 +156,4 @@
 	mapclear(h);
 	free(h->nodes);
 	free(h);
-}
\ No newline at end of file
+}