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>
**/
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;
}
}