In attachment "smarter" strlcmp. It doesn't use strlen and uses one condition
less in loop than previous version. When string is shorter than length
('\0' in the middle of string) results differ. Previous version is IMHO buggy.
I've too fast computer to judge which version is faster.
Results may vary for different data.

Could you check it?

Witold Filipczyk
--- src/util/string.c   2005-08-09 16:47:01.450227816 +0200
+++ src/util/string.c.2 2005-08-09 16:42:56.180514480 +0200
@@ -203,17 +203,22 @@
  \
        /* TODO: Don't precompute strlen()s but rather make the loop smarter.
         * --pasky */ \
-       if (n1 == -1) n1 = strlen(s1); \
-       if (n2 == -1) n2 = strlen(s2); \
+       /* if (n1 == -1) n1 = strlen(s1); */ \
+       /* if (n2 == -1) n2 = strlen(s2); */ \
  \
-       string_assert(errfile, errline, n1 >= 0 && n2 >= 0, c); \
+       /* string_assert(errfile, errline, n1 >= 0 && n2 >= 0, c); */ \
+       if (n1 == -1) n1 = n2; \
+       if (n2 == -1) n2 = n1; \
+       if (n1 > n2) n1 = n2; \
  \
-       d = n1 - n2; \
-       if (d) return d; \
+       /* d = n1 - n2; */ \
+       /* if (d) return d; */ \
  \
-       for (p = 0; p < n1 && s1[p] && s2[p]; p++) { \
+       /* for (p = 0; p < n1 && s1[p] && s2[p]; p++) { */ \
+       for (p = 0; p != n1; p++) { \
                d = t1 - t2; \
                if (d) return d; \
+               if (!s1[p]) return 0; \
        } \
        return 0; \
 }
_______________________________________________
elinks-dev mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-dev

Reply via email to