On Tue, May 19, 2015, at 15:30, Benno Schulenberg wrote:
> Do for example four times 'cat src/*.c >>testing.c' and then
> run 'src/nano testing.c'.  When then hitting Enter or ^K, it
> takes nano nearly a second to respond.

That first patch was a rough one.  Here is a better patch;
it avoids recalculating all the multiline data in some cases
when it's not needed.

It can probably be improved still further, but this one avoids
slowdowns when editing inside an area covered by a multiline
regex.  (To test, I run it on a tenfold concatenation of all
of nano's C source files.)

If you can, please test.

Benno

-- 
http://www.fastmail.com - Choose from over 50 domains or use your own

Index: src/proto.h
===================================================================
--- src/proto.h	(revision 5225)
+++ src/proto.h	(working copy)
@@ -142,6 +142,8 @@
 
 typedef void (*functionptrtype)(void);
 
+void precalc_multicolorinfo(void);
+
 /* All functions in browser.c. */
 #ifndef DISABLE_BROWSER
 char *do_browser(char *path, DIR *dir);
Index: src/color.c
===================================================================
--- src/color.c	(revision 5225)
+++ src/color.c	(working copy)
@@ -441,11 +441,8 @@
 	    continue;
 
 	alloc_multidata_if_needed(fileptr);
-	if (force == TRUE) {
-	    reset_multis_for_id(fileptr, tmpcolor->id);
-	    continue;
-	}
 
+	if (force == FALSE) {
 	/* Figure out where the first begin and end are to determine if
 	 * things changed drastically for the precalculated multi values. */
 	nobegin = regexec(tmpcolor->start, fileptr->data, 1, &startmatch, 0);
@@ -456,14 +453,20 @@
 	} else if (fileptr->multidata[tmpcolor->id] == CNONE) {
 	    if (nobegin && noend)
 		continue;
-	}  else if (fileptr->multidata[tmpcolor->id] & CBEGINBEFORE && !noend
-	  && (nobegin || endmatch.rm_eo > startmatch.rm_eo)) {
-	    reset_multis_after(fileptr, tmpcolor->id);
+	} else if (fileptr->multidata[tmpcolor->id] == CSTARTENDHERE &&
+			!nobegin && !noend && startmatch.rm_so < endmatch.rm_so) {
 	    continue;
+	} else if (fileptr->multidata[tmpcolor->id] == CBEGINBEFORE && nobegin && !noend) {
+	    continue;
+	} else if (fileptr->multidata[tmpcolor->id] == CENDAFTER && !nobegin && noend) {
+	    continue;
 	}
+	}
 
 	/* If we got here, assume the worst. */
-	reset_multis_for_id(fileptr, tmpcolor->id);
+	precalc_multicolorinfo();
+	edit_refresh_needed = TRUE;
+	break;
     }
 }
 
Index: src/winio.c
===================================================================
--- src/winio.c	(revision 5225)
+++ src/winio.c	(working copy)
@@ -2724,7 +2724,6 @@
 				/* We painted to the end of the line, so
 				 * don't bother checking any more
 				 * starts. */
-				fileptr->multidata[tmpcolor->id] = CENDAFTER;
 				break;
 			    }
 			}
Index: src/nano.c
===================================================================
--- src/nano.c	(revision 5225)
+++ src/nano.c	(working copy)
@@ -1880,6 +1880,7 @@
 #endif
 
 		alloc_multidata_if_needed(fileptr);
+		fileptr->multidata[tmpcolor->id] = 0;
 
 		if ((cur_check = time(NULL)) - last_check > 1) {
 		    last_check = cur_check;

Reply via email to