1
0
forked from aniani/vim

patch 9.1.1212: too many strlen() calls in edit.c

Problem:  too many strlen() calls in edit.c
Solution: refactor edit.c and remove strlen() calls
          (John Marriott)

This commit attempts to make edit.c more efficient by:

- in truncate_spaces() pass in the length of the string.
- return a string_T from get_last_insert(), so that the length of the
  string is available to the caller.
- refactor stuff_insert():

  - replace calls to stuffReadbuff() (which calls STRLEN() on it's
    string argument) with stuffReadbuffLen() (which gets the length of
    it's string argument passed in).
  - replace call to vim_strrchr() which searches from the start of the
    string with a loop which searches from end of the string to find the
    last ESC character.

- change get_last_insert_save() to call get_last_insert() to get the
  last_insert string (the logic is in one place).

closes: #16863

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-03-16 20:49:52 +01:00
committed by Christian Brabandt
parent 20d23ce93b
commit 34954972c2
6 changed files with 97 additions and 56 deletions

View File

@@ -2235,7 +2235,7 @@ open_line(
saved_line[curwin->w_cursor.col] = NUL;
// Remove trailing white space, unless OPENLINE_KEEPTRAIL used.
if (trunc_line && !(flags & OPENLINE_KEEPTRAIL))
truncate_spaces(saved_line);
truncate_spaces(saved_line, curwin->w_cursor.col);
ml_replace(curwin->w_cursor.lnum, saved_line, FALSE);
saved_line = NULL;
if (did_append)