code comparison optimization
authorLaurent Mazet <mazet@softndesign.org>
Mon, 16 Jan 2023 23:01:57 +0000 (00:01 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Mon, 16 Jan 2023 23:01:57 +0000 (00:01 +0100)
code.c

diff --git a/code.c b/code.c
index 5872443387b8048521ab189618e3ff813e8995f5..b8c8e78c7067cca3498dacda767185af1ed4fbe7 100644 (file)
--- a/code.c
+++ b/code.c
@@ -23,14 +23,12 @@ int codcat (char *dst, int n, char *src)
 
 int codcmp (char *cod1, char *cod2)
 {
-    int i = -1;
-
-    do {
-        i++;
-        if (cod1[i] != cod2[i]) {
-            return (cod1[i] < cod2[i]) ? -1 : 1;
+    while ((*cod1 != 0) || (*cod2 != 0)) {
+        int test = *cod1++ - *cod2++;
+        if (test != 0) {
+            return (test < 0) ? -1 : 1;
         }
-    } while (cod1[i] != 0);
+    }
 
     return 0;
 }