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
parent
ba2e6f43c2
commit
4e667bd048
10
src/chars.c
10
src/chars.c
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue