]> granicus.if.org Git - nethack/commitdiff
Refactor bones search loop
authorMichael Meyer <me@entrez.cc>
Thu, 31 Dec 2020 03:42:48 +0000 (22:42 -0500)
committerMichael Meyer <me@entrez.cc>
Thu, 31 Dec 2020 03:42:48 +0000 (22:42 -0500)
Using a for loop instead of an if and a do/while makes the code much
more clear and concise, so that it's easier to understand what the
function does at a glance.  The actual approach to iterating through the
current level's bones files and searching for a match is more or less
unchanged.

src/bones.c

index e0b81ed3d775662a3e00f40178d9755d53e97f31..d497343f49d0cd330a4524446c3d0651625fb0dd 100644 (file)
@@ -671,12 +671,11 @@ const char *name;
     Strcat(buf, "-");
     len = strlen(buf);
 
-    if ((bp = g.level.bonesinfo)) {
-        do {
-            if (!strncmp(bp->who, buf, len))
-                return TRUE;
-        } while ((bp = bp->next) != (struct cemetery *) 0);
+    for (bp = g.level.bonesinfo; bp; bp = bp->next) {
+        if (!strncmp(bp->who, buf, len))
+            return TRUE;
     }
+
     return FALSE;
 }