From 9d14187c95920670c0db5ccb47bdfe790482a3a7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 28 Sep 2020 12:31:13 +0200 Subject: [PATCH] lib: Remove an optimization in string_replace() Why? This simplifies the code. Why do I believe we can do this? I don't think this is a very common operation in critical code paths. Also, next_codepoint() already has the same optimization. If this turns out to be a measurable performance issue, we should turn next_codepoint() into a static inline function doing the 7-bit optimized code path inlined the same way we did it for tdb_oob(). This way all callers would benefit from this optimization. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- lib/util/util_str_common.c | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/lib/util/util_str_common.c b/lib/util/util_str_common.c index 1e93a46fbad..7bdba9a7a8c 100644 --- a/lib/util/util_str_common.c +++ b/lib/util/util_str_common.c @@ -72,40 +72,16 @@ _PUBLIC_ size_t ucs2_align(const void *base_ptr, const void *p, int flags) **/ void string_replace( char *s, char oldc, char newc ) { - char *p; - - /* 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 - (ie. they match for the first 128 chars) */ - - for (p = s; *p; p++) { - if (*p & 0x80) /* mb string - slow path. */ - break; - if (*p == oldc) { - *p = newc; - } - } - - if (!*p) - return; - - /* Slow (mb) path. */ -#ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS - /* With compose characters we must restart from the beginning. JRA. */ - p = s; -#endif - - while (*p) { + while (*s != '\0') { size_t c_size; - next_codepoint(p, &c_size); + next_codepoint(s, &c_size); if (c_size == 1) { - if (*p == oldc) { - *p = newc; + if (*s == oldc) { + *s = newc; } } - p += c_size; + s += c_size; } }