Blob Blame History Raw
From 7de236c3652431b12c3e9390fe47777317e93d6c Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Mon, 23 Jan 2017 14:41:25 +0100
Subject: [PATCH] painting: make use of the multidata of the preceding line

When painting a line, the multidata of the line /before/ it is valid
in most cases: it was determined just a moment ago.  And it tells us
all we need to know: whether there is an unpaired start match before
the current line or not.

The only exception is when painting the first line of the screen:
the multidata of the line before it might be stale.  So for the
first screen line we will always have to do some backtracking.
But that is left for later.

This fixes https://savannah.gnu.org/bugs/?50121.

Upstream-commit: b3bcc8eeac45a5ae249d3ff2fc198c190e198af2
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
---
 src/color.c |  3 +++
 src/winio.c | 24 +++++++++++++++++++++---
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/color.c b/src/color.c
index 39355ca..6b174e3 100644
--- a/src/color.c
+++ b/src/color.c
@@ -374,6 +374,9 @@ void reset_multis(filestruct *fileptr, bool force)
 		continue;
 	}
 
+	refresh_needed = TRUE;
+	return;
+
 	/* If we got here, things have changed. */
 	reset_multis_for_id(fileptr, tmpcolor->id);
     }
diff --git a/src/winio.c b/src/winio.c
index 731e8b5..e94fbd6 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2364,6 +2364,22 @@ void edit_draw(filestruct *fileptr, const char *converted, int
 		const filestruct *end_line;
 		    /* The line that matches 'end'. */
 
+		/* First check the multidata of the preceding line -- it tells
+		 * us about the situation so far, and thus what to do here. */
+		if (start_line != NULL && start_line->multidata != NULL) {
+		    if (start_line->multidata[varnish->id] == CWHOLELINE ||
+			    start_line->multidata[varnish->id] == CENDAFTER) {
+			fileptr->multidata[varnish->id] = CNONE;
+			goto seek_an_end;
+		    }
+		    if (start_line->multidata[varnish->id] == CNONE ||
+			    start_line->multidata[varnish->id] == CBEGINBEFORE ||
+			    start_line->multidata[varnish->id] == CSTARTENDHERE) {
+			fileptr->multidata[varnish->id] = CNONE;
+			goto step_two;
+		    }
+		}
+
 		/* First see if the multidata was maybe already calculated. */
 		if (fileptr->multidata[varnish->id] == CNONE)
 		    goto tail_of_loop;
@@ -2379,9 +2395,10 @@ void edit_draw(filestruct *fileptr, const char *converted, int
 			endmatch.rm_eo) - start);
 		    mvwaddnstr(edit, line, 0, converted, paintlen);
 		    goto tail_of_loop;
-		} if (fileptr->multidata[varnish->id] == -1)
-		    /* Assume this until proven otherwise below. */
-		    fileptr->multidata[varnish->id] = CNONE;
+		}
+
+		/* Assume nothing gets painted until proven otherwise below. */
+		fileptr->multidata[varnish->id] = CNONE;
 
 		/* There is no precalculated multidata, so find it out now.
 		 * First check if the beginning of the line is colored by a
@@ -2438,6 +2455,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int
 		}
 		/* Indeed, there is a start without an end on that line. */
 
+  seek_an_end:
 		/* We've already checked that there is no end before fileptr
 		 * and after the start.  But is there an end after the start
 		 * at all?  We don't paint unterminated starts. */
-- 
2.9.4