From a365288bcee80018a436ca15d5c9d272e772bb37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Sun, 11 Jul 2010 15:28:55 +0200 Subject: [PATCH 1/1] unistr/u8-strchr: Optimize ASCII argument case. --- ChangeLog | 6 ++++++ lib/unistr/u8-strchr.c | 27 +++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1207beff4..28b0b0f48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 --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; -- 2.11.0