]> granicus.if.org Git - graphviz/commitdiff
remove strncmp micro-optimization in rindexOf
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 24 Feb 2021 01:56:03 +0000 (17:56 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 2 Mar 2021 06:05:11 +0000 (22:05 -0800)
Compilers can do this trick themselves if they decide there is speed to be
gained from it.

lib/gvpr/actions.c

index 7b7566e944c1dd5663685c6fa322b50f53a9727a..4d3293a4200eca13a37fcb6692d96f67af2699cc 100644 (file)
@@ -65,7 +65,6 @@ int indexOf(char *s1, char *s2)
 int rindexOf(char *s1, char *s2)
 {
     char c1 = *s2;
-    char c;
     char *p;
     size_t len1 = strlen(s1);
     size_t len2 = strlen(s2);
@@ -76,8 +75,7 @@ int rindexOf(char *s1, char *s2)
        return -1;
     p = s1 + (len1 - len2);
     while (p >= s1) {
-       c = *p;
-       if ((c == c1) && (strncmp(p+1, s2+1, len2-1) == 0))
+       if (strncmp(p, s2, len2) == 0)
            return (p - s1);
        else
            p--;