From e7511abd8653834cb04fed3c7ba05661040d9fdb Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 25 Jun 2020 09:53:39 +0200 Subject: [PATCH] tweaks: avoid checking a variable three times for each pass in the loop --- src/search.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/search.c b/src/search.c index 89aa055e..f9667d1f 100644 --- 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. */