From 9f884810b6892f2cf633385c9435b441e715de73 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 13 Jan 2017 19:25:16 +0100 Subject: [PATCH] tweaks: use a subtraction instead of a counter And return a better value, so that less calculation is needed. --- src/winio.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/winio.c b/src/winio.c index bf6fdba9..b04625e7 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2664,8 +2664,6 @@ int update_line(filestruct *fileptr, size_t index) { int row = 0; /* The row in the edit window we will be updating. */ - int extra_rows = 0; - /* The number of extra rows a softwrapped line occupies. */ char *converted; /* The data of the line with tabs and control characters expanded. */ size_t from_col = 0; @@ -2691,6 +2689,7 @@ int update_line(filestruct *fileptr, size_t index) #ifndef NANO_TINY if (ISSET(SOFTWRAP)) { size_t full_length = strlenpt(fileptr->data); + int starting_row = row; for (from_col = 0; from_col <= full_length && row < editwinrows; from_col += editwincols) { @@ -2704,11 +2703,9 @@ int update_line(filestruct *fileptr, size_t index) /* Draw the line. */ edit_draw(fileptr, converted, row++, from_col); free(converted); - - extra_rows++; } - return --extra_rows; + return (row - starting_row); } #endif @@ -2731,7 +2728,7 @@ int update_line(filestruct *fileptr, size_t index) if (strlenpt(fileptr->data) > from_col + editwincols) mvwaddch(edit, row, COLS - 1, '$'); - return 0; + return 1; } /* Check whether old_column and new_column are on different "pages" (or that @@ -2945,9 +2942,9 @@ void edit_refresh(void) while (row < editwinrows && line != NULL) { if (line == openfile->current) - row += update_line(line, openfile->current_x) + 1; + row += update_line(line, openfile->current_x); else - row += update_line(line, 0) + 1; + row += update_line(line, 0); line = line->next; }