From 0508520b477a9612c9273491dd74418d299c8519 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 24 Jan 2021 16:56:31 +0100 Subject: [PATCH] tweaks: reshuffle three conditions into a better order When a zero-length match is beyond the width of the screen, there is no point in continuing evaluating the rule, so the check for "offscreen to the right" needs to come first. The check for a zero-width match needs to come second because otherwise we would get stuck on such a match when it is offscreen to the left. --- src/winio.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/winio.c b/src/winio.c index 8f1975ce..c65bbbc6 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2513,25 +2513,25 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) &match, (index == 0) ? 0 : REG_NOTBOL) != 0) break; - /* If the match is of length zero, skip over it. */ - if (match.rm_so == match.rm_eo) { - index = step_right(line->data, index + match.rm_eo); - continue; - } - /* Translate the match to the beginning of the line. */ match.rm_so += index; match.rm_eo += index; index = match.rm_eo; + /* If the match is offscreen to the right, this rule is done. */ + if (match.rm_so >= till_x) + break; + + /* If the match has length zero, advance over it. */ + if (match.rm_so == match.rm_eo) { + index = step_right(line->data, index); + continue; + } + /* If the match is offscreen to the left, skip to next. */ if (match.rm_eo <= from_x) continue; - /* If the match is off to the right, this rule is done. */ - if (match.rm_so >= till_x) - break; - if (match.rm_so > from_x) start_col = wideness(line->data, match.rm_so) - from_col;