From 055e262b56e42cf8d591851513b5e7ce324d2d31 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 24 Jan 2021 12:31:52 +0100 Subject: [PATCH] tweaks: stop evaluating a rule when the match is offscreen to the right When the match of a coloring regex is beyond the width of the screen, there is no point in continuing to evaluate the regex for the rest of the line, because any other matches will be offscreen too. This will save some time when there are several overlong lines. --- src/winio.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/winio.c b/src/winio.c index 5a034a34..fa3ae715 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2524,10 +2524,14 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) match.rm_eo += index; index = match.rm_eo; - /* If the matching part is not visible, skip it. */ - if (match.rm_eo <= from_x || match.rm_so >= till_x) + /* 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; + start_col = (match.rm_so <= from_x) ? 0 : wideness(line->data, match.rm_so) - from_col;