tweaks: again use memory on the stack instead of malloc() and free()
Also, don't bother copying the found bracket -- just compare it in situ and thus elide a variable.master
parent
aedc3ddd49
commit
b5bc1b5094
16
src/search.c
16
src/search.c
|
@ -994,7 +994,7 @@ void do_find_bracket(void)
|
|||
* the bracket at the current cursor position. */
|
||||
int wanted_ch_len;
|
||||
/* The length of wanted_ch in bytes. */
|
||||
char *bracket_set;
|
||||
char bracket_set[MAXCHARLEN * 2 + 1];
|
||||
/* The pair of characters in ch and wanted_ch. */
|
||||
size_t i;
|
||||
/* Generic loop variable. */
|
||||
|
@ -1008,8 +1008,6 @@ void do_find_bracket(void)
|
|||
/* The initial bracket count. */
|
||||
bool reverse;
|
||||
/* The direction we search. */
|
||||
char *found_ch;
|
||||
/* The character we find. */
|
||||
|
||||
assert(mbstrlen(matchbrackets) % 2 == 0);
|
||||
|
||||
|
@ -1057,20 +1055,16 @@ void do_find_bracket(void)
|
|||
wanted_ch_len = parse_mbchar(wanted_ch, NULL, NULL);
|
||||
|
||||
/* Fill bracket_set in with the values of ch and wanted_ch. */
|
||||
bracket_set = charalloc((MAXCHARLEN * 2) + 1);
|
||||
strncpy(bracket_set, ch, ch_len);
|
||||
strncpy(bracket_set + ch_len, wanted_ch, wanted_ch_len);
|
||||
bracket_set[ch_len + wanted_ch_len] = '\0';
|
||||
|
||||
found_ch = charalloc(MAXCHARLEN + 1);
|
||||
|
||||
while (TRUE) {
|
||||
if (find_bracket_match(reverse, bracket_set)) {
|
||||
/* If we found an identical bracket, increment count. If we
|
||||
* found a complementary bracket, decrement it. */
|
||||
parse_mbchar(openfile->current->data + openfile->current_x,
|
||||
found_ch, NULL);
|
||||
count += (strncmp(found_ch, ch, ch_len) == 0) ? 1 : -1;
|
||||
count += (strncmp(openfile->current->data + openfile->current_x,
|
||||
ch, ch_len) == 0) ? 1 : -1;
|
||||
|
||||
/* If count is zero, we've found a matching bracket. Update
|
||||
* the screen and get out. */
|
||||
|
@ -1088,10 +1082,6 @@ void do_find_bracket(void)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up. */
|
||||
free(bracket_set);
|
||||
free(found_ch);
|
||||
}
|
||||
#endif /* !NANO_TINY */
|
||||
|
||||
|
|
Loading…
Reference in New Issue