nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 9d8388e8367fc6003eb3c13ed8fc44fe0b4a28eb
parent 895de17a582f4298a9e2af85bf2c9ea2aa58108e
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sat, 23 Jan 2021 17:20:32 +0100

tweaks: call wattron()/wattroff() only when actually painting something

A syntax has on average a dozen coloring rules, but on average maybe
three or four pieces of text (rough estimate) in a line get painted.
So, on average, it is cheaper to call wattron() and wattroff() only
when actually coloring a piece of text, instead of calling wattron()
before starting to evaluate each rule and wattroff() after finishing
its evaluation.

Diffstat:
Msrc/winio.c | 21++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/winio.c b/src/winio.c @@ -2505,8 +2505,6 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) regmatch_t startmatch, endmatch; /* The match positions of the start and end regexes. */ - wattron(edit, varnish->attributes); - /* First case: varnish is a single-line expression. */ if (varnish->end == NULL) { while (index < till_x) { @@ -2539,9 +2537,12 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) paintlen = actual_x(thetext, wideness(line->data, match.rm_eo) - from_col - start_col); + wattron(edit, varnish->attributes); mvwaddnstr(edit, row, margin + start_col, thetext, paintlen); + wattroff(edit, varnish->attributes); } - goto tail_of_loop; + + continue; } /* Second case: varnish is a multiline expression. */ @@ -2622,21 +2623,25 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) /* If there is no end, there is nothing to paint. */ if (end_line == NULL) { line->multidata[varnish->id] = CWOULDBE; - goto tail_of_loop; + continue; } /* If the end is on a later line, paint whole line, and be done. */ if (end_line != line) { + wattron(edit, varnish->attributes); mvwaddnstr(edit, row, margin, converted, -1); + wattroff(edit, varnish->attributes); line->multidata[varnish->id] = CWHOLELINE; - goto tail_of_loop; + continue; } /* Only if it is visible, paint the part to be coloured. */ if (endmatch.rm_eo > from_x) { paintlen = actual_x(converted, wideness(line->data, endmatch.rm_eo) - from_col); + wattron(edit, varnish->attributes); mvwaddnstr(edit, row, margin, converted, paintlen); + wattroff(edit, varnish->attributes); } line->multidata[varnish->id] = CBEGINBEFORE; @@ -2673,8 +2678,10 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) paintlen = actual_x(thetext, wideness(line->data, endmatch.rm_eo) - from_col - start_col); + wattron(edit, varnish->attributes); mvwaddnstr(edit, row, margin + start_col, thetext, paintlen); + wattroff(edit, varnish->attributes); line->multidata[varnish->id] = CSTARTENDHERE; } @@ -2703,12 +2710,12 @@ void draw_row(int row, const char *converted, linestruct *line, size_t from_col) } /* Paint the rest of the line, and we're done. */ + wattron(edit, varnish->attributes); mvwaddnstr(edit, row, margin + start_col, thetext, -1); + wattroff(edit, varnish->attributes); line->multidata[varnish->id] = CENDAFTER; break; } - tail_of_loop: - wattroff(edit, varnish->attributes); } } #endif /* ENABLE_COLOR */