commit 7be76af418c923095d9cdebe67abc5d2f063fe41
parent fb17929fabaa5184c183dac482cee1285f949e72
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 9 Jun 2019 10:47:30 +0200
tweaks: speed up the counting of characters in mbstrlen()
This function is used in get_totsize(), so speed is important.
There is no reason why the length of the string must limited to a
certain size -- that is just a leftover from the function merge in
commit ba2e6f43 from a year ago.
Diffstat:
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/src/chars.c b/src/chars.c
@@ -506,13 +506,9 @@ char *mbrevstrcasestr(const char *haystack, const char *needle,
/* Count the number of (multibyte) characters in the given string. */
size_t mbstrlen(const char *s)
{
- size_t maxlen = (size_t)-1;
-
-#ifdef ENABLE_UTF8
- if (use_utf8) {
size_t n = 0;
- while (*s != '\0' && maxlen > 0) {
+ while (*s != '\0') {
if ((signed char)*s < 0) {
int length = mblen(s, MAXCHARLEN);
@@ -520,14 +516,10 @@ size_t mbstrlen(const char *s)
} else
s++;
- maxlen--;
n++;
}
return n;
- } else
-#endif
- return strnlen(s, maxlen);
}
#if !defined(NANO_TINY) || defined(ENABLE_JUSTIFY)