tweaks: reduce the counting of characters to just the needed function

Evade the indirect use of the general-purpose function parse_mbchar().
This reduces the counting time by roughly ten percent.
master
Benno Schulenberg 2018-06-03 17:58:05 +02:00
parent ba2e6f43c2
commit 4e667bd048
1 changed files with 7 additions and 3 deletions

View File

@ -539,9 +539,13 @@ size_t mbstrlen(const char *s)
if (use_utf8) {
size_t n = 0;
for (; *s != '\0' && maxlen > 0; s += move_mbright(s, 0),
maxlen--, n++)
;
while (*s != '\0' && maxlen > 0) {
int length = mblen(s, MAXCHARLEN);
s += (length < 0 ? 1 : length);
maxlen--;
n++;
}
return n;
} else