diff options
author | VanaIgr <vanaigranov@gmail.com> | 2023-12-18 20:57:04 -0600 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2024-01-22 09:04:45 +0800 |
commit | cdf848a314bf91a0c87c717f9a44742dea877515 (patch) | |
tree | 3dda7a0c7117944ce95b4f2237fdcf9c066af131 /src/nvim/mouse.c | |
parent | b5653984e5de514410b5654d2a9b92bdcb9eedf3 (diff) | |
download | rneovim-cdf848a314bf91a0c87c717f9a44742dea877515.tar.gz rneovim-cdf848a314bf91a0c87c717f9a44742dea877515.tar.bz2 rneovim-cdf848a314bf91a0c87c717f9a44742dea877515.zip |
perf: reuse fast character size calculation algorithm from getvcol()
Diffstat (limited to 'src/nvim/mouse.c')
-rw-r--r-- | src/nvim/mouse.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index a6da7dd3c7..86de182aee 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -1755,22 +1755,23 @@ colnr_T vcol2col(win_T *wp, linenr_T lnum, colnr_T vcol, colnr_T *coladdp) { // try to advance to the specified column char *line = ml_get_buf(wp->w_buffer, lnum); - chartabsize_T cts; - init_chartabsize_arg(&cts, wp, lnum, 0, line, line); - while (cts.cts_vcol < vcol && *cts.cts_ptr != NUL) { - int size = win_lbr_chartabsize(&cts, NULL); - if (cts.cts_vcol + size > vcol) { + CharsizeArg arg; + CSType cstype = init_charsize_arg(&arg, wp, lnum, line); + StrCharInfo ci = utf_ptr2StrCharInfo(line); + int cur_vcol = 0; + while (cur_vcol < vcol && *ci.ptr != NUL) { + int next_vcol = cur_vcol + win_charsize(cstype, cur_vcol, ci.ptr, ci.chr.value, &arg).width; + if (next_vcol > vcol) { break; } - cts.cts_vcol += size; - MB_PTR_ADV(cts.cts_ptr); + cur_vcol = next_vcol; + ci = utfc_next(ci); } - clear_chartabsize_arg(&cts); if (coladdp != NULL) { - *coladdp = vcol - cts.cts_vcol; + *coladdp = vcol - cur_vcol; } - return (colnr_T)(cts.cts_ptr - line); + return (colnr_T)(ci.ptr - line); } /// Set UI mouse depending on current mode and 'mouse'. |