1
0
forked from aniani/vim

patch 9.1.1151: too many strlen() calls in getchar.c

Problem:  too many strlen() calls in getchar.c
Solution: store last inserted and recorded lengths,
          add functions to retrieve those and use those
          functions (John Marriott)

closes: #16720

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
John Marriott
2025-02-25 20:56:38 +01:00
committed by Christian Brabandt
parent 580e457a2a
commit d3c4b7e946
5 changed files with 48 additions and 18 deletions

View File

@@ -421,7 +421,7 @@ edit(
new_insert_skip = 0;
else
{
new_insert_skip = (int)STRLEN(ptr);
new_insert_skip = (int)get_inserted_len();
vim_free(ptr);
}
@@ -2462,7 +2462,7 @@ stop_insert(
* otherwise CTRL-O w and then <Left> will clear "last_insert".
*/
ptr = get_inserted();
int added = ptr == NULL ? 0 : (int)STRLEN(ptr) - new_insert_skip;
int added = ptr == NULL ? 0 : (int)get_inserted_len() - new_insert_skip;
if (did_restart_edit == 0 || added > 0)
{
vim_free(last_insert);
@@ -2993,11 +2993,11 @@ get_last_insert_save(void)
if (last_insert == NULL)
return NULL;
s = vim_strsave(last_insert + last_insert_skip);
len = (int)STRLEN(last_insert + last_insert_skip);
s = vim_strnsave(last_insert + last_insert_skip, len);
if (s == NULL)
return NULL;
len = (int)STRLEN(s);
if (len > 0 && s[len - 1] == ESC) // remove trailing ESC
s[len - 1] = NUL;
return s;