commit e7511abd8653834cb04fed3c7ba05661040d9fdb
parent b1b89f01b7010452b0ea8413a8a3451708ddd541
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Thu, 25 Jun 2020 09:53:39 +0200
tweaks: avoid checking a variable three times for each pass in the loop
Diffstat:
1 file changed, 12 insertions(+), 19 deletions(-)
diff --git a/src/search.c b/src/search.c
@@ -882,27 +882,20 @@ bool find_a_bracket(bool reverse, const char *bracket_pair)
pointer = line->data + step_right(line->data, openfile->current_x);
/* Now seek for any of the two brackets, either backwards or forwards. */
- while (TRUE) {
- if (reverse)
- found = mbrevstrpbrk(line->data, bracket_pair, pointer);
- else
- found = mbstrpbrk(pointer, bracket_pair);
-
- if (found)
- break;
-
- if (reverse)
+ if (reverse) {
+ while (!(found = mbrevstrpbrk(line->data, bracket_pair, pointer))) {
line = line->prev;
- else
+ if (line == NULL)
+ return FALSE;
+ pointer = line->data + strlen(line->data);
+ }
+ } else {
+ while (!(found = mbstrpbrk(pointer, bracket_pair))) {
line = line->next;
-
- /* If we've reached the start or end of the buffer, get out. */
- if (line == NULL)
- return FALSE;
-
- pointer = line->data;
- if (reverse)
- pointer += strlen(line->data);
+ if (line == NULL)
+ return FALSE;
+ pointer = line->data;
+ }
}
/* Set the current position to the found bracket. */