diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-28 10:30:08 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-03-28 10:30:08 +0100 |
commit | 8ede7a069419e0e01368c65a2d0c79d6332aa6cd (patch) | |
tree | 8b6a70866e924d99d8710de10828fa42a78f13cf /src/edit.c | |
parent | 2ca7d5f4831ce3d86cdc3f0c844fc50ea0deb7e5 (diff) |
patch 9.1.0218: Unnecessary multiplications in backspace codev9.1.0218
Problem: Unnecessary multiplications in backspace code, as
"col / ts * ts" is the same as "col - col % ts".
Solution: Change "col / ts * ts" to "col - col % ts". Adjust the loop
and the comments ins_bs() to be easier to understand. Update
tests to reset 'smarttab' properly.
(zeertzjq)
closes: #14308
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/edit.c')
-rw-r--r-- | src/edit.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/edit.c b/src/edit.c index 56643a9d7a..efa32f51e7 100644 --- a/src/edit.c +++ b/src/edit.c @@ -4210,12 +4210,11 @@ ins_bs( && (!*inserted_space_p || arrow_used)))))) { - int ts; colnr_T vcol = 0; colnr_T want_vcol; char_u *line; char_u *ptr; - char_u *end_ptr; + char_u *cursor_ptr; char_u *space_ptr; colnr_T space_vcol = 0; int prev_space = FALSE; @@ -4224,11 +4223,13 @@ ins_bs( *inserted_space_p = FALSE; space_ptr = ptr = line = ml_get_curline(); - end_ptr = line + curwin->w_cursor.col; + cursor_ptr = line + curwin->w_cursor.col; - // Find the last whitespace that is preceded by non-whitespace. + // Compute virtual column of cursor position, and find the last + // whitespace before cursor that is preceded by non-whitespace. // Use chartabsize() so that virtual text and wrapping are ignored. - do { + while (ptr < cursor_ptr) + { int cur_space = VIM_ISWHITE(*ptr); if (!prev_space && cur_space) @@ -4239,25 +4240,18 @@ ins_bs( vcol += chartabsize(ptr, vcol); MB_PTR_ADV(ptr); prev_space = cur_space; - } while (ptr < end_ptr); + } // Compute the virtual column where we want to be. - want_vcol = vcol - 1; -#ifdef FEAT_VARTABS + want_vcol = vcol > 0 ? vcol - 1 : 0; if (p_sta && in_indent) - { - ts = (int)get_sw_value(curbuf); - want_vcol = (want_vcol / ts) * ts; - } + want_vcol -= want_vcol % (int)get_sw_value(curbuf); else +#ifdef FEAT_VARTABS want_vcol = tabstop_start(want_vcol, get_sts_value(), curbuf->b_p_vsts_array); #else - if (p_sta && in_indent) - ts = (int)get_sw_value(curbuf); - else - ts = (int)get_sts_value(); - want_vcol = (want_vcol / ts) * ts; + want_vcol -= want_vcol % (int)get_sts_value(); #endif // Find the position to stop backspacing. |