From 78bfc9223a69daae8d69a0b28a6cf891ab65a25e Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 13 May 2020 12:29:44 +0200 Subject: [PATCH] tweaks: add a condition, so that two ifs can be elided Now all functions that are relevant only to softwrapping get called only when softwrapping is on. This also allows to elide an intermediate function call. --- src/move.c | 4 ++-- src/winio.c | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/move.c b/src/move.c index 1657bda9..7338df12 100644 --- a/src/move.c +++ b/src/move.c @@ -556,8 +556,8 @@ void do_scroll_down(void) if (editwinrows > 1 && (openfile->edittop->next != NULL #ifndef NANO_TINY - || chunk_for(openfile->firstcolumn, openfile->edittop) < - number_of_chunks_in(openfile->edittop) + || (ISSET(SOFTWRAP) && (number_of_chunks_in(openfile->edittop) > + chunk_for(openfile->firstcolumn, openfile->edittop))) #endif )) edit_scroll(FORWARD); diff --git a/src/winio.c b/src/winio.c index 8f1f8c76..ef24f6a5 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3098,31 +3098,25 @@ size_t get_chunk_and_edge(size_t column, linestruct *line, size_t *leftedge) * relative to the first row (zero-based). */ size_t chunk_for(size_t column, linestruct *line) { - if (ISSET(SOFTWRAP)) - return get_chunk_and_edge(column, line, NULL); - else - return 0; + return get_chunk_and_edge(column, line, NULL); } /* Return the leftmost column of the softwrapped chunk of the given line that * column is on. */ size_t leftedge_for(size_t column, linestruct *line) { - if (ISSET(SOFTWRAP)) { - size_t leftedge; + size_t leftedge; - get_chunk_and_edge(column, line, &leftedge); + get_chunk_and_edge(column, line, &leftedge); - return leftedge; - } else - return 0; + return leftedge; } /* Return the row of the last softwrapped chunk of the given line, relative to * the first row (zero-based). */ size_t number_of_chunks_in(linestruct *line) { - return chunk_for((size_t)-1, line); + return get_chunk_and_edge((size_t)-1, line, NULL); } /* Ensure that firstcolumn is at the starting column of the softwrapped chunk