aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/edit.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-03-10 17:08:00 +0800
committerGitHub <noreply@github.com>2024-03-10 17:08:00 +0800
commitb465ede2c7a4fb39cf84682d645a3acd08631010 (patch)
tree8e1ed7028f6a138f6fd54e31f5d19d316013449b /src/nvim/edit.c
parenta441bdc936f9258851be3fa04c108c37e0a497ab (diff)
downloadrneovim-b465ede2c7a4fb39cf84682d645a3acd08631010.tar.gz
rneovim-b465ede2c7a4fb39cf84682d645a3acd08631010.tar.bz2
rneovim-b465ede2c7a4fb39cf84682d645a3acd08631010.zip
vim-patch:9.1.0138: too many STRLEN calls when getting a memline (#27799)
Problem: too many STRLEN calls when getting a memline Solution: Optimize calls to STRLEN(), add a few functions in memline.c that return the byte length instead of relying on STRLEN() (John Marriott) closes: vim/vim#14052 https://github.com/vim/vim/commit/02d7a6c6cfceb3faf9c98fcb7c458760cd50d269 Cherry-pick line break changes from patch 8.1.0226. Cherry-pick ml_line_len from patch 8.1.0579. Cherry-pick test_comments.vim change from patch 9.1.0153. Co-authored-by: John Marriott <basilisk@internode.on.net>
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r--src/nvim/edit.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index b7b32883c2..54deb0f1c3 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -3785,9 +3785,10 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
if (has_format_option(FO_AUTO)
&& has_format_option(FO_WHITE_PAR)) {
char *ptr = ml_get_buf_mut(curbuf, curwin->w_cursor.lnum);
- int len = (int)strlen(ptr);
+ int len = get_cursor_line_len();
if (len > 0 && ptr[len - 1] == ' ') {
ptr[len - 1] = NUL;
+ curbuf->b_ml.ml_line_len--;
}
}
@@ -4411,13 +4412,13 @@ static bool ins_tab(void)
if (i > 0) {
STRMOVE(ptr, ptr + i);
// correct replace stack.
- if ((State & REPLACE_FLAG)
- && !(State & VREPLACE_FLAG)) {
+ if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG)) {
for (temp = i; --temp >= 0;) {
replace_join(repl_off);
}
}
if (!(State & VREPLACE_FLAG)) {
+ curbuf->b_ml.ml_line_len -= i;
inserted_bytes(fpos.lnum, change_col,
cursor->col - change_col, fpos.col - change_col);
}
@@ -4462,8 +4463,7 @@ bool ins_eol(int c)
// Strange Vi behaviour: In Replace mode, typing a NL will not delete the
// character under the cursor. Only push a NUL on the replace stack,
// nothing to put back when the NL is deleted.
- if ((State & REPLACE_FLAG)
- && !(State & VREPLACE_FLAG)) {
+ if ((State & REPLACE_FLAG) && !(State & VREPLACE_FLAG)) {
replace_push(NUL);
}