diff mbox

[2/3] Use strdiff in strcasecmp.

Message ID 20150513100402.GA1051@domone
State New
Headers show

Commit Message

Ondřej Bílka May 13, 2015, 10:04 a.m. UTC
Hi, this optimizes strcasecmp to look for first mismatch which would
likely fail in caseless case. We don't have to handle encoding as
comparison is done bytewise.

Is this ok? Now there isn't performance improvement as strdiff isn't yet
optimized. I will add optimized strdiff in next patch.


	* string/strcasecmp.c (__strcasecmp): Use strdiff.
diff mbox

Patch

diff --git a/string/strcasecmp.c b/string/strcasecmp.c
index 6b14912..5d1e27e 100644
--- a/string/strcasecmp.c
+++ b/string/strcasecmp.c
@@ -41,6 +41,10 @@ 
 # define LOCALE_PARAM_DECL
 #endif
 
+#define STRING_TYPE char
+#define USTRING_TYPE unsigned char
+#include <string/strdiff.h>
+
 /* Compare S1 and S2, ignoring case, returning less than, equal to or
    greater than zero if S1 is lexicographically less than,
    equal to or greater than S2.  */
@@ -53,12 +57,13 @@  __strcasecmp (s1, s2 LOCALE_PARAM)
 #if defined _LIBC && !defined USE_IN_EXTENDED_LOCALE_MODEL
   __locale_t loc = _NL_CURRENT_LOCALE;
 #endif
+
+  STRDIFF_L (&s1, &s2, __cet_8bit);
+
   const unsigned char *p1 = (const unsigned char *) s1;
   const unsigned char *p2 = (const unsigned char *) s2;
   int result;
 
-  if (p1 == p2)
-    return 0;
 
   while ((result = TOLOWER (*p1) - TOLOWER (*p2++)) == 0)
     if (*p1++ == '\0')