nano

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

commit d365ca80bf613201332ac06fe7a39866321a2814
parent f1d214c0ef0ec781bae87544851b9d53893d6df5
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Thu, 23 Feb 2017 21:27:01 +0100

tweaks: optimize determining the number of columns that a text spans

Give the strlenpt() routine its own implementation, so that it avoids
a needless comparison plus subtraction in the inner loop.

Diffstat:
Msrc/utils.c | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/utils.c b/src/utils.c @@ -520,11 +520,15 @@ size_t strnlenpt(const char *text, size_t maxlen) return width; } -/* A strlen() with tabs and multicolumn characters factored in: - * how many columns wide is text? */ +/* Return the number of columns that the given text occupies. */ size_t strlenpt(const char *text) { - return strnlenpt(text, (size_t)-1); + size_t span = 0; + + while (*text != '\0') + text += parse_mbchar(text, NULL, &span); + + return span; } /* Append a new magicline to filebot. */