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>
diff --git a/src/proto/edit.pro b/src/proto/edit.pro
index f918528..170ac97 100644
--- a/src/proto/edit.pro
+++ b/src/proto/edit.pro
@@ -7,7 +7,7 @@
void edit_unputchar(void);
void display_dollar(colnr_T col_arg);
void undisplay_dollar(void);
-void truncate_spaces(char_u *line);
+void truncate_spaces(char_u *line, size_t len);
void backspace_until_column(int col);
int get_literal(int noReduceKeys);
void insertchar(int c, int flags, int second_indent);
@@ -24,7 +24,7 @@
void cursor_down_inner(win_T *wp, long n);
int cursor_down(long n, int upd_topline);
int stuff_inserted(int c, long count, int no_esc);
-char_u *get_last_insert(void);
+string_T *get_last_insert(void);
char_u *get_last_insert_save(void);
void replace_push(int c);
int replace_push_mb(char_u *p);