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.
master
Benno Schulenberg 2020-01-26 20:01:34 +01:00
parent 6ae11071b3
commit 0442eef95b
1 changed files with 6 additions and 2 deletions

View File

@ -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);