1
0
forked from aniani/vim

patch 9.1.1137: ins_str() is inefficient by calling STRLEN()

Problem:  ins_str() is inefficient by calling STRLLEN()
Solution: refactor ins_str() to take a length argument
          and let all callers provide the correct length
          when calling ins_str() (John Marriott)

closes: #16711

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-23 09:09:59 +01:00
committed by Christian Brabandt
parent 066a5340e3
commit f4b36417e8
9 changed files with 46 additions and 39 deletions

View File

@@ -1178,10 +1178,9 @@ ins_char_bytes(char_u *buf, int charlen)
* Caller must have prepared for undo.
*/
void
ins_str(char_u *s)
ins_str(char_u *s, size_t slen)
{
char_u *oldp, *newp;
int newlen = (int)STRLEN(s);
int oldlen;
colnr_T col;
linenr_T lnum = curwin->w_cursor.lnum;
@@ -1193,16 +1192,16 @@ ins_str(char_u *s)
oldp = ml_get(lnum);
oldlen = (int)ml_get_len(lnum);
newp = alloc(oldlen + newlen + 1);
newp = alloc(oldlen + slen + 1);
if (newp == NULL)
return;
if (col > 0)
mch_memmove(newp, oldp, (size_t)col);
mch_memmove(newp + col, s, (size_t)newlen);
mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
mch_memmove(newp + col, s, slen);
mch_memmove(newp + col + slen, oldp + col, (size_t)(oldlen - col + 1));
ml_replace(lnum, newp, FALSE);
inserted_bytes(lnum, col, newlen);
curwin->w_cursor.col += newlen;
inserted_bytes(lnum, col, slen);
curwin->w_cursor.col += slen;
}
/*