aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cmdhist.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-05-21 06:22:23 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-05-22 06:37:26 +0800
commitb86381f425223adf0ff91fa0746914a5774ddabb (patch)
tree3a954980956a6ac250fc2e1a875802d5057bddde /src/nvim/cmdhist.c
parent879d17ea8d62c199ea0c91c5f37a4f25495be7ce (diff)
downloadrneovim-b86381f425223adf0ff91fa0746914a5774ddabb.tar.gz
rneovim-b86381f425223adf0ff91fa0746914a5774ddabb.tar.bz2
rneovim-b86381f425223adf0ff91fa0746914a5774ddabb.zip
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 https://github.com/vim/vim/commit/8c85a2a49acf80e4f53ec51e6ff2a5f3830eeddb Co-authored-by: John Marriott <basilisk@internode.on.net>
Diffstat (limited to 'src/nvim/cmdhist.c')
-rw-r--r--src/nvim/cmdhist.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/nvim/cmdhist.c b/src/nvim/cmdhist.c
index 6a9290270a..eb1658aa1f 100644
--- a/src/nvim/cmdhist.c
+++ b/src/nvim/cmdhist.c
@@ -294,7 +294,7 @@ static int last_maptick = -1; // last seen maptick
/// @param histype may be one of the HIST_ values.
/// @param in_map consider maptick when inside a mapping
/// @param sep separator character used (search hist)
-void add_to_history(int histype, const char *new_entry, int in_map, int sep)
+void add_to_history(int histype, const char *new_entry, size_t new_entrylen, bool in_map, int sep)
{
histentry_T *hisptr;
@@ -334,11 +334,10 @@ void add_to_history(int histype, const char *new_entry, int in_map, int sep)
hist_free_entry(hisptr);
// Store the separator after the NUL of the string.
- size_t len = strlen(new_entry);
- hisptr->hisstr = xstrnsave(new_entry, len + 2);
+ hisptr->hisstr = xstrnsave(new_entry, new_entrylen + 2);
hisptr->timestamp = os_time();
hisptr->additional_elements = NULL;
- hisptr->hisstr[len + 1] = (char)sep;
+ hisptr->hisstr[new_entrylen + 1] = (char)sep;
hisptr->hisnum = ++hisnum[histype];
if (histype == HIST_SEARCH && in_map) {
@@ -536,7 +535,7 @@ void f_histadd(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
}
init_history();
- add_to_history(histype, str, false, NUL);
+ add_to_history(histype, str, strlen(str), false, NUL);
rettv->vval.v_number = true;
}