From 4e667bd048c813a410eea7e68a2b7c0c980330ee Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 3 Jun 2018 17:58:05 +0200 Subject: [PATCH] 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. --- src/chars.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/chars.c b/src/chars.c index 7fc3e82b..31641e7f 100644 --- a/src/chars.c +++ b/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