From: Bruno Haible Date: Sun, 18 Jul 2010 15:23:36 +0000 (+0200) Subject: unistr/u8-strchr: Optimize non-ASCII argument case. X-Git-Tag: v0.1~4017 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=e240ab433593692f27c804c26ec1730a0dd27e5d unistr/u8-strchr: Optimize non-ASCII argument case. --- diff --git a/ChangeLog b/ChangeLog index 72b38a4b7..8fb3e771f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-07-18 Bruno Haible + + 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 . + 2010-07-15 Karl Berry * config/srclist.txt (fdl.texi): only one copy, from gnustandards. diff --git a/lib/unistr/u8-strchr.c b/lib/unistr/u8-strchr.c index 0b5e993d1..3ee246521 100644 --- a/lib/unistr/u8-strchr.c +++ b/lib/unistr/u8-strchr.c @@ -68,7 +68,7 @@ u8_strchr (const uint8_t *s, ucs4_t uc) { 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 @@ u8_strchr (const uint8_t *s, ucs4_t uc) { 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 @@ u8_strchr (const uint8_t *s, ucs4_t uc) { 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;