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: #14796
Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/cmdhist.c b/src/cmdhist.c
index 6342f02..7cdcee6 100644
--- a/src/cmdhist.c
+++ b/src/cmdhist.c
@@ -297,11 +297,11 @@
add_to_history(
int histype,
char_u *new_entry,
+ size_t new_entrylen,
int in_map, // consider maptick when inside a mapping
int sep) // separator character used (search hist)
{
histentry_T *hisptr;
- int len;
if (hislen == 0) // no history
return;
@@ -336,10 +336,9 @@
vim_free(hisptr->hisstr);
// Store the separator after the NUL of the string.
- len = (int)STRLEN(new_entry);
- hisptr->hisstr = vim_strnsave(new_entry, len + 2);
+ hisptr->hisstr = vim_strnsave(new_entry, new_entrylen + 2);
if (hisptr->hisstr != NULL)
- hisptr->hisstr[len + 1] = sep;
+ hisptr->hisstr[new_entrylen + 1] = sep;
hisptr->hisnum = ++hisnum[histype];
hisptr->viminfo = FALSE;
@@ -566,7 +565,7 @@
return;
init_history();
- add_to_history(histype, str, FALSE, NUL);
+ add_to_history(histype, str, STRLEN(str), FALSE, NUL);
rettv->vval.v_number = TRUE;
}