commit 1bbf07b27e790fb224e629f9cf103974659e6885
parent b9deb883fae414e4ae99ec9cf6b386e74f9bb9e1
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 1 May 2020 13:52:25 +0200
color: avoid allocating emptiness when there are no multiline regexes
When a file is saved under a different name, and as a result the
applicable syntax changes, and the old syntax had multiline regexes
and the new syntax doesn't, then the call of precalc_multicolorinfo()
in write_file() should not result in nano setting up a multicache of
zero bytes for each line in the buffer.
(Problem was found by locally letting nano crash when zero bytes are
allocated, and then happening to rename a file.py to a file.sh.)
Diffstat:
2 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/color.c b/src/color.c
@@ -315,7 +315,8 @@ void precalc_multicolorinfo(void)
regmatch_t startmatch, endmatch;
linestruct *line, *tailline;
- if (openfile->syntax == NULL || ISSET(NO_SYNTAX))
+ if (openfile->syntax == NULL || openfile->syntax->nmultis == 0 ||
+ openfile->filetop->multidata || ISSET(NO_SYNTAX))
return;
/* For each line, allocate cache space for the multiline-regex info. */
diff --git a/src/files.c b/src/files.c
@@ -497,12 +497,8 @@ void prepare_for_display(void)
titlebar(NULL);
#ifdef ENABLE_COLOR
- /* If there are multiline coloring regexes, and there is no
- * multiline cache data yet, precalculate it now. */
- if (openfile->syntax && openfile->syntax->nmultis > 0 &&
- openfile->filetop->multidata == NULL)
- precalc_multicolorinfo();
-
+ /* Precalculate the data for any multiline coloring regexes. */
+ precalc_multicolorinfo();
have_palette = FALSE;
#endif
refresh_needed = TRUE;