# HG changeset patch # User Pádraig Brady # Date 1278854935 -7200 # Node ID 3142ae3b5707c9399d8eecd02a6762b34dd58f85 # Parent 2d23d5e447a1e813bf76b7a310a24f4df23cb12a unistr/u8-strchr: Optimize ASCII argument case. diff -r 2d23d5e447a1 -r 3142ae3b5707 ChangeLog --- a/ChangeLog Thu Jul 08 18:16:40 2010 -0700 +++ b/ChangeLog Sun Jul 11 15:28:55 2010 +0200 @@ -1,3 +1,9 @@ +2010-07-11 Pádraig Brady + Bruno Haible + + unistr/u8-strchr: Optimize ASCII argument case. + * lib/unistr/u8-strchr.c (u8_strchr): For ASCII arguments, use strchr. + 2010-07-08 Paul Eggert (x)memcoll: minor tweaks diff -r 2d23d5e447a1 -r 3142ae3b5707 lib/unistr/u8-strchr.c --- a/lib/unistr/u8-strchr.c Thu Jul 08 18:16:40 2010 -0700 +++ b/lib/unistr/u8-strchr.c Sun Jul 11 15:28:55 2010 +0200 @@ -21,6 +21,8 @@ /* Specification. */ #include "unistr.h" +#include + 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;