]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
micro-optimisation in m_libcbase.c cmp functions
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 26 Jul 2012 22:44:07 +0000 (22:44 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Thu, 26 Jul 2012 22:44:07 +0000 (22:44 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12790

coregrind/m_libcbase.c

index c7a189240c2e200694aaf137b94813f0621c9b21..118b3913542b7ab007d20a43411c6a42893e74fc 100644 (file)
@@ -303,13 +303,12 @@ Char* VG_(strncpy) ( Char* dest, const Char* src, SizeT ndest )
 Int VG_(strcmp) ( const Char* s1, const Char* s2 )
 {
    while (True) {
-      if (*s1 == 0 && *s2 == 0) return 0;
-      if (*s1 == 0) return -1;
-      if (*s2 == 0) return 1;
-
       if (*(UChar*)s1 < *(UChar*)s2) return -1;
       if (*(UChar*)s1 > *(UChar*)s2) return 1;
 
+      /* *s1 == *s2 */
+      if (*s1 == 0) return 0;
+
       s1++; s2++;
    }
 }
@@ -319,12 +318,11 @@ Int VG_(strcasecmp) ( const Char* s1, const Char* s2 )
    while (True) {
       UChar c1 = (UChar)VG_(tolower)(*s1);
       UChar c2 = (UChar)VG_(tolower)(*s2);
-      if (c1 == 0 && c2 == 0) return 0;
-      if (c1 == 0) return -1;
-      if (c2 == 0) return 1;
-
       if (c1 < c2) return -1;
       if (c1 > c2) return 1;
+      
+      /* c1 == c2 */
+      if (c1 == 0) return 0;
 
       s1++; s2++;
    }
@@ -335,12 +333,11 @@ Int VG_(strncmp) ( const Char* s1, const Char* s2, SizeT nmax )
    SizeT n = 0;
    while (True) {
       if (n >= nmax) return 0;
-      if (*s1 == 0 && *s2 == 0) return 0;
-      if (*s1 == 0) return -1;
-      if (*s2 == 0) return 1;
-
       if (*(UChar*)s1 < *(UChar*)s2) return -1;
       if (*(UChar*)s1 > *(UChar*)s2) return 1;
+      
+      /* *s1 == *s2 */
+      if (*s1 == 0) return 0;
 
       s1++; s2++; n++;
    }
@@ -355,13 +352,12 @@ Int VG_(strncasecmp) ( const Char* s1, const Char* s2, SizeT nmax )
       if (n >= nmax) return 0;
       c1 = (UChar)VG_(tolower)(*s1);
       c2 = (UChar)VG_(tolower)(*s2);
-      if (c1 == 0 && c2 == 0) return 0;
-      if (c1 == 0) return -1;
-      if (c2 == 0) return 1;
-
       if (c1 < c2) return -1;
       if (c1 > c2) return 1;
 
+      /* c1 == c2 */
+      if (c1 == 0) return 0;
+
       s1++; s2++; n++;
    }
 }