From b2cd6300d7a575ea01758233ab42b3bf205d20e1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 24 Sep 2004 01:32:19 +0000 Subject: r2578: Pick up optimisation from Samba4 - thanks tridge ! - I recently found out that charaters below 0x3F are guaranteed not to occur as secondary bytes in any multi-byte character set. This allows for a very simple optimisation in strchr_m() and strrchr_m(). It might be a good idea to pick this up for Samba3. Jeremy. (This used to be commit 0465e2d23d27e535bad4652037b37041049bfa96) --- source3/lib/util_str.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 65a616ad41..2c0cae1d73 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1208,6 +1208,12 @@ char *strchr_m(const char *src, char c) smb_ucs2_t *p; const char *s; + /* characters below 0x3F are guaranteed to not appear in + non-initial position in multi-byte charsets */ + if ((c & 0xC0) == 0) { + return strchr(s, c); + } + /* this is quite a common operation, so we want it to be fast. We optimise for the ascii case, knowing that all our supported multi-byte character sets are ascii-compatible @@ -1237,6 +1243,12 @@ char *strchr_m(const char *src, char c) char *strrchr_m(const char *s, char c) { + /* characters below 0x3F are guaranteed to not appear in + non-initial position in multi-byte charsets */ + if ((c & 0xC0) == 0) { + return strrchr(s, c); + } + /* this is quite a common operation, so we want it to be fast. We optimise for the ascii case, knowing that all our supported multi-byte character sets are ascii-compatible -- cgit