Mercurial > hg > octave-lyh > gnulib-hg
changeset 13454:24850bb5c424
unistr/u8-strchr: Optimize ASCII argument case.
author | Pádraig Brady <P@draigBrady.com> |
---|---|
date | Sun, 11 Jul 2010 15:28:55 +0200 |
parents | c5416617cfbf |
children | 215879220d76 |
files | ChangeLog lib/unistr/u8-strchr.c |
diffstat | 2 files changed, 27 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-07-11 Pádraig Brady <P@draigBrady.com> + Bruno Haible <bruno@clisp.org> + + unistr/u8-strchr: Optimize ASCII argument case. + * lib/unistr/u8-strchr.c (u8_strchr): For ASCII arguments, use strchr. + 2010-07-08 Paul Eggert <eggert@cs.ucla.edu> (x)memcoll: minor tweaks
--- a/lib/unistr/u8-strchr.c +++ b/lib/unistr/u8-strchr.c @@ -21,6 +21,8 @@ /* Specification. */ #include "unistr.h" +#include <string.h> + uint8_t * u8_strchr (const uint8_t *s, ucs4_t uc) { @@ -30,18 +32,31 @@ { uint8_t c0 = uc; - for (;; s++) + if (false) { - if (*s == c0) - break; - if (*s == 0) - goto notfound; + /* Unoptimized code. */ + for (;; s++) + { + if (*s == c0) + break; + if (*s == 0) + goto notfound; + } + return (uint8_t *) s; } - return (uint8_t *) s; + else + { + /* Optimized code. + strchr() is often so well optimized, that it's worth the + added function call. */ + return (uint8_t *) strchr ((const char *) s, c0); + } } else switch (u8_uctomb_aux (c, uc, 6)) { + /* Loops equivalent to strstr, optimized for a specific length (2, 3, 4) + of the needle. */ case 2: if (*s == 0) goto notfound;