vim-patch:9.1.0426: too many strlen() calls in search.c

Problem:  too many strlen() calls in search.c
Solution: refactor code and remove more strlen() calls,
          use explicit variable to remember strlen
          (John Marriott)

closes: vim/vim#14796

8c85a2a49a

Co-authored-by: John Marriott <basilisk@internode.on.net>
This commit is contained in:
zeertzjq
2024-05-21 06:22:23 +08:00
parent 879d17ea8d
commit b86381f425
13 changed files with 279 additions and 194 deletions

View File

@@ -2665,16 +2665,16 @@ void ex_spellrepall(exarg_T *eap)
const size_t repl_to_len = strlen(repl_to);
const int addlen = (int)(repl_to_len - repl_from_len);
const size_t frompatlen = repl_from_len + 7;
char *frompat = xmalloc(frompatlen);
snprintf(frompat, frompatlen, "\\V\\<%s\\>", repl_from);
const size_t frompatsize = repl_from_len + 7;
char *frompat = xmalloc(frompatsize);
size_t frompatlen = (size_t)snprintf(frompat, frompatsize, "\\V\\<%s\\>", repl_from);
p_ws = false;
sub_nsubs = 0;
sub_nlines = 0;
curwin->w_cursor.lnum = 0;
while (!got_int) {
if (do_search(NULL, '/', '/', frompat, 1, SEARCH_KEEP, NULL) == 0
if (do_search(NULL, '/', '/', frompat, frompatlen, 1, SEARCH_KEEP, NULL) == 0
|| u_save_cursor() == FAIL) {
break;
}