aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/cursor.c
diff options
context:
space:
mode:
authorVanaIgr <vanaigranov@gmail.com>2023-12-18 20:57:04 -0600
committerzeertzjq <zeertzjq@outlook.com>2024-01-22 09:04:45 +0800
commitcdf848a314bf91a0c87c717f9a44742dea877515 (patch)
tree3dda7a0c7117944ce95b4f2237fdcf9c066af131 /src/nvim/cursor.c
parentb5653984e5de514410b5654d2a9b92bdcb9eedf3 (diff)
downloadrneovim-cdf848a314bf91a0c87c717f9a44742dea877515.tar.gz
rneovim-cdf848a314bf91a0c87c717f9a44742dea877515.tar.bz2
rneovim-cdf848a314bf91a0c87c717f9a44742dea877515.zip
perf: reuse fast character size calculation algorithm from getvcol()
Diffstat (limited to 'src/nvim/cursor.c')
-rw-r--r--src/nvim/cursor.c21
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