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.
master
Benno Schulenberg 2016-12-15 16:45:26 +01:00
parent fc101a6ded
commit 85ebe971e2
1 changed files with 2 additions and 3 deletions

View File

@ -382,11 +382,10 @@ int parse_mbchar(const char *buf, char *chr, size_t *col)
length = mblen(buf, MB_CUR_MAX); length = mblen(buf, MB_CUR_MAX);
/* When the multibyte sequence is invalid, only take the first byte. */ /* When the multibyte sequence is invalid, only take the first byte. */
if (length < 0) { if (length <= 0) {
IGNORE_CALL_RESULT(mblen(NULL, 0)); IGNORE_CALL_RESULT(mblen(NULL, 0));
length = 1; length = 1;
} else if (length == 0) }
length = 1;
/* When requested, store the multibyte character in chr. */ /* When requested, store the multibyte character in chr. */
if (chr != NULL) { if (chr != NULL) {