mirror of
https://github.com/samba-team/samba.git
synced 2025-01-10 01:18:15 +03:00
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 <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
parent
2c04e9a6f2
commit
9d14187c95
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user