changeset 13470:f309a1831a56

unistr/u8-strchr: Optimize non-ASCII argument case.
author Bruno Haible <bruno@clisp.org>
date Sun, 18 Jul 2010 17:23:36 +0200
parents 8c198b17bc8c
children 7ade914695f0
files ChangeLog lib/unistr/u8-strchr.c
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-07-18  Bruno Haible  <bruno@clisp.org>
+
+	unistr/u8-strchr: Optimize non-ASCII argument case.
+	* lib/unistr/u8-strchr.c (u8_strchr): Compare the last byte first,
+	because the first byte often matches anyway.
+	Reported by Pádraig Brady <P@draigbrady.com>.
+
 2010-07-15  Karl Berry  <karl@gnu.org>
 
 	* config/srclist.txt (fdl.texi): only one copy, from gnustandards.
--- a/lib/unistr/u8-strchr.c
+++ b/lib/unistr/u8-strchr.c
@@ -68,7 +68,7 @@
             {
               if (s[1] == 0)
                 goto notfound;
-              if (*s == c0 && s[1] == c1)
+              if (s[1] == c1 && *s == c0)
                 break;
             }
           return (uint8_t *) s;
@@ -86,7 +86,7 @@
             {
               if (s[2] == 0)
                 goto notfound;
-              if (*s == c0 && s[1] == c1 && s[2] == c2)
+              if (s[2] == c2 && s[1] == c1 && *s == c0)
                 break;
             }
           return (uint8_t *) s;
@@ -105,7 +105,7 @@
             {
               if (s[3] == 0)
                 goto notfound;
-              if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3)
+              if (s[3] == c3 && s[2] == c2 && s[1] == c1 && *s == c0)
                 break;
             }
           return (uint8_t *) s;