From 3c695664ecf25ec1b67c9918db57b4075e7f3f89 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 21 Oct 2019 15:37:43 +0200 Subject: [PATCH] tweaks: elide a function call for the plain ASCII case When dealing with a plain, seven-bit ASCII character, don't bother calling is_cntrl_mbchar() but determine directly whether it is a control character. Also reshuffle things so that we don't compare charlen == 1 when we already know it is 1. --- src/chars.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/chars.c b/src/chars.c index 51ea080b..d81f5a03 100644 --- a/src/chars.c +++ b/src/chars.c @@ -314,29 +314,39 @@ int collect_char(const char *string, char *thechar) * the given string, and add this character's width to *column. */ int advance_over(const char *string, size_t *column) { - int charlen; - #ifdef ENABLE_UTF8 if ((signed char)*string < 0) { - charlen = mblen(string, MAXCHARLEN); - if (charlen <= 0) + int charlen = mblen(string, MAXCHARLEN); + + if (charlen > 0) { + if (is_cntrl_mbchar(string)) + *column += 2; + else + *column += mbwidth(string); + } else { charlen = 1; - } else -#endif - charlen = 1; + *column += 1; + } - if (*string == '\t') - *column += tabsize - *column % tabsize; - else if (is_cntrl_mbchar(string)) + return charlen; + } +#endif + + if ((unsigned char)*string < 0x20) { + if (*string == '\t') + *column += tabsize - *column % tabsize; + else + *column += 2; + } else if (*string == 0x7F) + *column += 2; +#ifndef ENABLE_UTF8 + else if (0x7F < (unsigned char)*string && (unsigned char)*string < 0xA0) *column += 2; - else if (charlen == 1) - *column += 1; -#ifdef ENABLE_UTF8 - else - *column += mbwidth(string); #endif + else + *column += 1; - return charlen; + return 1; } /* Return the index in buf of the beginning of the multibyte character