nano

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

commit 0442eef95b2855c07545c02fcd5cb4661a9ee657
parent 6ae11071b3c25ac223182fab406b620255f085ef
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sun, 26 Jan 2020 20:01:34 +0100

tweaks: elide a somewhat costly call by remembering some state

When having prepared a line for displaying on the screen, nano already
determind whether the line extends beyond the right edge or not.  There
is no need to calculate again the full width of the current line later.
Just let display_string() make a note whether the piece of text that
it converted to displayable form still has more text coming after it,
and use this note when it's time to show the ">" continuation sign.

Using a static variable is ugly, but passing it along as a parameter
would be even uglier, because for all other calls of display_string()
the parameter would be just a useless burden.

Diffstat:
Msrc/winio.c | 8++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/winio.c b/src/winio.c @@ -53,6 +53,8 @@ static int statusblank = 0; static bool seen_wide = FALSE; /* Whether we've seen a multicolumn character in the current line. */ #endif +static bool has_more = FALSE; + /* Whether the current line has more text after the displayed part. */ static bool reveal_cursor = FALSE; /* Whether the cursor should be shown when waiting for input. */ #ifndef NANO_TINY @@ -1977,7 +1979,9 @@ char *display_string(const char *buf, size_t column, size_t span, #else index--; #endif - } + has_more = TRUE; + } else + has_more = FALSE; is_shorter = (column < beyond); @@ -2769,7 +2773,7 @@ int update_line(linestruct *line, size_t index) mvwaddch(edit, row, margin, '<'); wattroff(edit, hilite_attribute); } - if (breadth(line->data) > from_col + editwincols) { + if (has_more) { wattron(edit, hilite_attribute); mvwaddch(edit, row, COLS - 1, '>'); wattroff(edit, hilite_attribute);