X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Funistr%2Fu8-strchr.c;h=0b5e993d1d5a6932d8d7eef943dfce5e85a9b399;hb=a365288bcee80018a436ca15d5c9d272e772bb37;hp=3be14c798325c1614aa3e6bf837e4112c09ba962;hpb=277aeb362143c763a4297d67c3ce55923649a6bd;p=gnulib.git diff --git a/lib/unistr/u8-strchr.c b/lib/unistr/u8-strchr.c index 3be14c798..0b5e993d1 100644 --- a/lib/unistr/u8-strchr.c +++ b/lib/unistr/u8-strchr.c @@ -21,6 +21,8 @@ /* Specification. */ #include "unistr.h" +#include + uint8_t * u8_strchr (const uint8_t *s, ucs4_t uc) { @@ -30,18 +32,31 @@ u8_strchr (const uint8_t *s, ucs4_t uc) { uint8_t c0 = uc; - for (;; s++) + if (false) + { + /* Unoptimized code. */ + for (;; s++) + { + if (*s == c0) + break; + if (*s == 0) + goto notfound; + } + return (uint8_t *) s; + } + else { - if (*s == c0) - break; - if (*s == 0) - goto notfound; + /* Optimized code. + strchr() is often so well optimized, that it's worth the + added function call. */ + return (uint8_t *) strchr ((const char *) s, c0); } - return (uint8_t *) s; } 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;