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

@@ -470,7 +470,7 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state
.sa_tm = &tm,
};
found = do_search(NULL, firstc == ':' ? '/' : firstc, search_delim,
ccline.cmdbuff + skiplen, count,
ccline.cmdbuff + skiplen, (size_t)patlen, count,
search_flags, &sia);
ccline.cmdbuff[skiplen + patlen] = next_char;
emsg_off--;
@@ -884,11 +884,12 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear
&& ccline.cmdlen
&& s->firstc != NUL
&& (s->some_key_typed || s->histype == HIST_SEARCH)) {
add_to_history(s->histype, ccline.cmdbuff, true,
size_t cmdbufflen = strlen(ccline.cmdbuff);
add_to_history(s->histype, ccline.cmdbuff, cmdbufflen, true,
s->histype == HIST_SEARCH ? s->firstc : NUL);
if (s->firstc == ':') {
xfree(new_last_cmdline);
new_last_cmdline = xstrdup(ccline.cmdbuff);
new_last_cmdline = xstrnsave(ccline.cmdbuff, cmdbufflen);
}
}
@@ -1451,7 +1452,7 @@ static int may_do_command_line_next_incsearch(int firstc, int count, incsearch_s
pat[patlen] = NUL;
int found = searchit(curwin, curbuf, &t, NULL,
next_match ? FORWARD : BACKWARD,
pat, count, search_flags,
pat, (size_t)patlen, count, search_flags,
RE_SEARCH, NULL);
emsg_off--;
pat[patlen] = save;