From 85ebe971e205084655a8abeaff42e3b0ff27d752 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 15 Dec 2016 16:45:26 +0100 Subject: [PATCH] chars: optimize for the most common case That is: elide a second test from the most travelled path: a valid character. This adds a second call of mblen() when parse_mbchar() is called on a terminating zero, but that should never happen. --- src/chars.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/chars.c b/src/chars.c index b65e8955..badb1082 100644 --- a/src/chars.c +++ b/src/chars.c @@ -382,11 +382,10 @@ int parse_mbchar(const char *buf, char *chr, size_t *col) length = mblen(buf, MB_CUR_MAX); /* When the multibyte sequence is invalid, only take the first byte. */ - if (length < 0) { + if (length <= 0) { IGNORE_CALL_RESULT(mblen(NULL, 0)); length = 1; - } else if (length == 0) - length = 1; + } /* When requested, store the multibyte character in chr. */ if (chr != NULL) {