nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 3c695664ecf25ec1b67c9918db57b4075e7f3f89
parent 8a7634f07007c7681e77ff9c2c5def9e2a45e5db
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Mon, 21 Oct 2019 15:37:43 +0200

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.

Diffstat:
Msrc/chars.c | 40+++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 15 deletions(-)

diff --git 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 + *column += 1; + } + + return charlen; + } #endif - charlen = 1; - if (*string == '\t') - *column += tabsize - *column % tabsize; - else if (is_cntrl_mbchar(string)) + 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