diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-10 17:08:00 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-10 17:08:00 +0800 |
commit | b465ede2c7a4fb39cf84682d645a3acd08631010 (patch) | |
tree | 8e1ed7028f6a138f6fd54e31f5d19d316013449b /src/nvim/change.c | |
parent | a441bdc936f9258851be3fa04c108c37e0a497ab (diff) | |
download | rneovim-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/change.c')
-rw-r--r-- | src/nvim/change.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c index 1c7724f010..b914bc29fe 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -926,21 +926,24 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) count = oldlen - col; movelen = 1; } + colnr_T newlen = oldlen - count; // If the old line has been allocated the deletion can be done in the // existing line. Otherwise a new line has to be allocated. - bool was_alloced = ml_line_alloced(); // check if oldp was allocated + bool alloc_newp = !ml_line_alloced(); // check if oldp was allocated char *newp; - if (was_alloced) { + if (!alloc_newp) { ml_add_deleted_len(curbuf->b_ml.ml_line_ptr, oldlen); newp = oldp; // use same allocated memory } else { // need to allocate a new line - newp = xmalloc((size_t)(oldlen + 1 - count)); + newp = xmalloc((size_t)newlen + 1); memmove(newp, oldp, (size_t)col); } memmove(newp + col, oldp + col + count, (size_t)movelen); - if (!was_alloced) { + if (alloc_newp) { ml_replace(lnum, newp, false); + } else { + curbuf->b_ml.ml_line_len -= count; } // mark the buffer as changed and prepare for displaying |