mirror of
git://git.sv.gnu.org/nano.git
synced 2025-03-22 01:13:02 +03:00
tweaks: use a cheaper way to detect an end-of-line
There is no need to compute the line length: just avoid overstepping the terminating NUL byte when being forced to advance the index.
This commit is contained in:
parent
414a1ecc8d
commit
775f007348
13
src/color.c
13
src/color.c
@ -414,7 +414,6 @@ void precalc_multicolorinfo(void)
|
|||||||
|
|
||||||
for (line = openfile->fileage; line != NULL; line = line->next) {
|
for (line = openfile->fileage; line != NULL; line = line->next) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int linelen = strlen(line->data);
|
|
||||||
|
|
||||||
alloc_multidata_if_needed(line);
|
alloc_multidata_if_needed(line);
|
||||||
/* Assume nothing applies until proven otherwise below. */
|
/* Assume nothing applies until proven otherwise below. */
|
||||||
@ -424,11 +423,9 @@ void precalc_multicolorinfo(void)
|
|||||||
* found, mark all the lines that are affected. */
|
* found, mark all the lines that are affected. */
|
||||||
while (regexec(ink->start, line->data + index, 1,
|
while (regexec(ink->start, line->data + index, 1,
|
||||||
&startmatch, (index == 0) ? 0 : REG_NOTBOL) == 0) {
|
&startmatch, (index == 0) ? 0 : REG_NOTBOL) == 0) {
|
||||||
|
/* Begin looking for an end match after the start match. */
|
||||||
index += startmatch.rm_eo;
|
index += startmatch.rm_eo;
|
||||||
|
|
||||||
if (index > linelen)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* If there is an end match on this line, mark the line, but
|
/* If there is an end match on this line, mark the line, but
|
||||||
* continue looking for other starts after it. */
|
* continue looking for other starts after it. */
|
||||||
if (regexec(ink->end, line->data + index, 1,
|
if (regexec(ink->end, line->data + index, 1,
|
||||||
@ -437,8 +434,12 @@ void precalc_multicolorinfo(void)
|
|||||||
index += endmatch.rm_eo;
|
index += endmatch.rm_eo;
|
||||||
/* If both start and end are mere anchors, step ahead. */
|
/* If both start and end are mere anchors, step ahead. */
|
||||||
if (startmatch.rm_so == startmatch.rm_eo &&
|
if (startmatch.rm_so == startmatch.rm_eo &&
|
||||||
endmatch.rm_so == endmatch.rm_eo)
|
endmatch.rm_so == endmatch.rm_eo) {
|
||||||
index += 1;
|
/* When at end-of-line, we're done. */
|
||||||
|
if (line->data[index] == '\0')
|
||||||
|
break;
|
||||||
|
index = move_mbright(line->data, index);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/winio.c
18
src/winio.c
@ -2419,8 +2419,6 @@ void edit_draw(filestruct *fileptr, const char *converted,
|
|||||||
/* The line that matches 'end'. */
|
/* The line that matches 'end'. */
|
||||||
regmatch_t startmatch, endmatch;
|
regmatch_t startmatch, endmatch;
|
||||||
/* The match positions of the start and end regexes. */
|
/* The match positions of the start and end regexes. */
|
||||||
int linelen;
|
|
||||||
/* The length of the line we are currently looking at. */
|
|
||||||
|
|
||||||
/* First see if the multidata was maybe already calculated. */
|
/* First see if the multidata was maybe already calculated. */
|
||||||
if (fileptr->multidata[varnish->id] == CNONE)
|
if (fileptr->multidata[varnish->id] == CNONE)
|
||||||
@ -2476,8 +2474,6 @@ void edit_draw(filestruct *fileptr, const char *converted,
|
|||||||
start_line->multidata[varnish->id] == CSTARTENDHERE))
|
start_line->multidata[varnish->id] == CSTARTENDHERE))
|
||||||
goto step_two;
|
goto step_two;
|
||||||
|
|
||||||
linelen = strlen(start_line->data);
|
|
||||||
|
|
||||||
/* Now start_line is the first line before fileptr containing
|
/* Now start_line is the first line before fileptr containing
|
||||||
* a start match. Is there a start on that line not followed
|
* a start match. Is there a start on that line not followed
|
||||||
* by an end on that line? */
|
* by an end on that line? */
|
||||||
@ -2486,9 +2482,9 @@ void edit_draw(filestruct *fileptr, const char *converted,
|
|||||||
index += startmatch.rm_eo;
|
index += startmatch.rm_eo;
|
||||||
/* If the start match is of length zero, step ahead. */
|
/* If the start match is of length zero, step ahead. */
|
||||||
if (startmatch.rm_so == startmatch.rm_eo) {
|
if (startmatch.rm_so == startmatch.rm_eo) {
|
||||||
index = move_mbright(start_line->data, index);
|
if (start_line->data[index] == '\0')
|
||||||
if (index > linelen)
|
|
||||||
break;
|
break;
|
||||||
|
index = move_mbright(start_line->data, index);
|
||||||
}
|
}
|
||||||
/* If there is no end after this last start, good. */
|
/* If there is no end after this last start, good. */
|
||||||
if (regexec(varnish->end, start_line->data + index,
|
if (regexec(varnish->end, start_line->data + index,
|
||||||
@ -2498,9 +2494,9 @@ void edit_draw(filestruct *fileptr, const char *converted,
|
|||||||
index += endmatch.rm_eo;
|
index += endmatch.rm_eo;
|
||||||
/* If the end match is of length zero, step ahead. */
|
/* If the end match is of length zero, step ahead. */
|
||||||
if (endmatch.rm_so == endmatch.rm_eo) {
|
if (endmatch.rm_so == endmatch.rm_eo) {
|
||||||
index = move_mbright(start_line->data, index);
|
if (start_line->data[index] == '\0')
|
||||||
if (index > linelen)
|
|
||||||
break;
|
break;
|
||||||
|
index = move_mbright(start_line->data, index);
|
||||||
}
|
}
|
||||||
/* If there is no later start on this line, next step. */
|
/* If there is no later start on this line, next step. */
|
||||||
if (regexec(varnish->start, start_line->data + index,
|
if (regexec(varnish->start, start_line->data + index,
|
||||||
@ -2545,8 +2541,6 @@ void edit_draw(filestruct *fileptr, const char *converted,
|
|||||||
* looking only after an end match, if there is one. */
|
* looking only after an end match, if there is one. */
|
||||||
index = (paintlen == 0) ? 0 : endmatch.rm_eo;
|
index = (paintlen == 0) ? 0 : endmatch.rm_eo;
|
||||||
|
|
||||||
linelen = strlen(fileptr->data);
|
|
||||||
|
|
||||||
while (regexec(varnish->start, fileptr->data + index,
|
while (regexec(varnish->start, fileptr->data + index,
|
||||||
1, &startmatch, (index == 0) ?
|
1, &startmatch, (index == 0) ?
|
||||||
0 : REG_NOTBOL) == 0) {
|
0 : REG_NOTBOL) == 0) {
|
||||||
@ -2586,9 +2580,9 @@ void edit_draw(filestruct *fileptr, const char *converted,
|
|||||||
index = endmatch.rm_eo;
|
index = endmatch.rm_eo;
|
||||||
/* If the end match is of length zero, step ahead. */
|
/* If the end match is of length zero, step ahead. */
|
||||||
if (endmatch.rm_so == endmatch.rm_eo) {
|
if (endmatch.rm_so == endmatch.rm_eo) {
|
||||||
index = move_mbright(fileptr->data, index);
|
if (fileptr->data[index] == '\0')
|
||||||
if (index > linelen)
|
|
||||||
break;
|
break;
|
||||||
|
index = move_mbright(fileptr->data, index);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user