tweaks: do a check up front instead of every time round the loop
Instead of doing a check every time round the loop when it is useful only the first time, duplicate a bit a code and do the check and its related action beforehand. Also, improve some comments.
Этот коммит содержится в:
родитель
790ce3791a
Коммит
580fd13424
25
src/search.c
25
src/search.c
@ -862,26 +862,29 @@ void do_gotolinecolumn_void(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* Search, startting from the current position, for any of the two characters
|
/* Search, starting from the current position, for any of the two characters
|
||||||
* in bracket_set. If reverse is TRUE, search backwards, otherwise forwards.
|
* in bracket_set. If reverse is TRUE, search backwards, otherwise forwards.
|
||||||
* Return TRUE when a match was found, and FALSE otherwise. */
|
* Return TRUE when one of the brackets was found, and FALSE otherwise. */
|
||||||
bool find_bracket_match(bool reverse, const char *bracket_set)
|
bool find_bracket_match(bool reverse, const char *bracket_set)
|
||||||
{
|
{
|
||||||
linestruct *line = openfile->current;
|
linestruct *line = openfile->current;
|
||||||
const char *pointer = line->data + openfile->current_x;
|
const char *pointer = line->data + openfile->current_x;
|
||||||
const char *found = NULL;
|
const char *found = NULL;
|
||||||
|
|
||||||
/* The pointer might end up one character before the start of the line.
|
/* Step away from the current bracket, either backwards or forwards. */
|
||||||
* This is not a problem: it will be skipped over below in the loop. */
|
if (reverse) {
|
||||||
if (reverse)
|
if (--pointer < line->data) {
|
||||||
--pointer;
|
line = line->prev;
|
||||||
else
|
if (line == NULL)
|
||||||
|
return FALSE;
|
||||||
|
pointer = line->data + strlen(line->data);
|
||||||
|
}
|
||||||
|
} else
|
||||||
++pointer;
|
++pointer;
|
||||||
|
|
||||||
|
/* Now seek for any of the two brackets, either backwards or forwards. */
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (pointer < line->data)
|
if (reverse)
|
||||||
found = NULL;
|
|
||||||
else if (reverse)
|
|
||||||
found = mbrevstrpbrk(line->data, bracket_set, pointer);
|
found = mbrevstrpbrk(line->data, bracket_set, pointer);
|
||||||
else
|
else
|
||||||
found = mbstrpbrk(pointer, bracket_set);
|
found = mbstrpbrk(pointer, bracket_set);
|
||||||
@ -903,7 +906,7 @@ bool find_bracket_match(bool reverse, const char *bracket_set)
|
|||||||
pointer += strlen(line->data);
|
pointer += strlen(line->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set the current position to the found matching bracket. */
|
/* Set the current position to the found bracket. */
|
||||||
openfile->current = line;
|
openfile->current = line;
|
||||||
openfile->current_x = found - line->data;
|
openfile->current_x = found - line->data;
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user