diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-01-22 10:00:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-22 10:00:11 +0800 |
commit | 8c6de9147cabbf99d18afbdbed2f11f30c1d0dfc (patch) | |
tree | b05e873236f53b2b9dc244c00f538eb47f45ab2f /src/nvim/cursor.c | |
parent | a25aeee856e2fb02f93ffa5c2e5d43fd75ead2cf (diff) | |
parent | fd08de4b85ae42fe3ad5b480b58df9f7fff76269 (diff) | |
download | rneovim-8c6de9147cabbf99d18afbdbed2f11f30c1d0dfc.tar.gz rneovim-8c6de9147cabbf99d18afbdbed2f11f30c1d0dfc.tar.bz2 rneovim-8c6de9147cabbf99d18afbdbed2f11f30c1d0dfc.zip |
Merge pull request #26813 from VanaIgr/screen-pos-speedup
perf: make screen size and position calculations more efficient
N/A patches for version.c:
vim-patch:9.1.0037: Calling get_breakindent_win() repeatedly when computing virtcol
vim-patch:9.1.0038: Unnecessary loop in getvcol()
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r-- | src/nvim/cursor.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index d8a63c1d7b..6c0a81838f 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -141,17 +141,18 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a } } - chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); - while (cts.cts_vcol <= wcol && *cts.cts_ptr != NUL) { - // Count a tab for what it's worth (if list mode not on) - csize = win_lbr_chartabsize(&cts, &head); - MB_PTR_ADV(cts.cts_ptr); - cts.cts_vcol += csize; + CharsizeArg arg; + CSType cstype = init_charsize_arg(&arg, curwin, pos->lnum, line); + StrCharInfo ci = utf_ptr2StrCharInfo(line); + col = 0; + while (col <= wcol && *ci.ptr != NUL) { + CharSize cs = win_charsize(cstype, col, ci.ptr, ci.chr.value, &arg); + csize = cs.width; + head = cs.head; + col += cs.width; + ci = utfc_next(ci); } - col = cts.cts_vcol; - idx = (int)(cts.cts_ptr - line); - clear_chartabsize_arg(&cts); + idx = (int)(ci.ptr - line); // Handle all the special cases. The virtual_active() check // is needed to ensure that a virtual position off the end of |