mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.1.0038: Unnecessary loop in getvcol()
Problem: Unnecessary loop in getvcol(). Solution: Compare next char position with pos->col directly. (zeertzjq) The loop below already handles end of line before checking for posptr, and the next char is after pos->col whether pos->col is at the start or in the middle of the char in question, so neither the NUL check nor the mb_head_off() are needed when comparing the position of the next char with pos->col directly. closes: #13878 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
5b0722b864
commit
4ea37f88e8
@ -1493,7 +1493,6 @@ getvcol(
|
|||||||
{
|
{
|
||||||
colnr_T vcol;
|
colnr_T vcol;
|
||||||
char_u *ptr; // points to current char
|
char_u *ptr; // points to current char
|
||||||
char_u *posptr; // points to char at pos->col
|
|
||||||
char_u *line; // start of the line
|
char_u *line; // start of the line
|
||||||
int incr;
|
int incr;
|
||||||
int head;
|
int head;
|
||||||
@ -1509,24 +1508,6 @@ getvcol(
|
|||||||
|
|
||||||
vcol = 0;
|
vcol = 0;
|
||||||
line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
|
line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
|
||||||
if (pos->col == MAXCOL)
|
|
||||||
posptr = NULL; // continue until the NUL
|
|
||||||
else
|
|
||||||
{
|
|
||||||
colnr_T i;
|
|
||||||
|
|
||||||
// In a few cases the position can be beyond the end of the line.
|
|
||||||
for (i = 0; i < pos->col; ++i)
|
|
||||||
if (ptr[i] == NUL)
|
|
||||||
{
|
|
||||||
pos->col = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
posptr = ptr + pos->col;
|
|
||||||
if (has_mbyte)
|
|
||||||
// always start on the first byte
|
|
||||||
posptr -= (*mb_head_off)(line, posptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
init_chartabsize_arg(&cts, wp, pos->lnum, 0, line, line);
|
init_chartabsize_arg(&cts, wp, pos->lnum, 0, line, line);
|
||||||
cts.cts_max_head_vcol = -1;
|
cts.cts_max_head_vcol = -1;
|
||||||
@ -1588,11 +1569,12 @@ getvcol(
|
|||||||
incr = g_chartab[c] & CT_CELL_MASK;
|
incr = g_chartab[c] & CT_CELL_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (posptr != NULL && ptr >= posptr) // character at pos->col
|
char_u *next_ptr = ptr + (*mb_ptr2len)(ptr);
|
||||||
|
if (next_ptr - line > pos->col) // character at pos->col
|
||||||
break;
|
break;
|
||||||
|
|
||||||
vcol += incr;
|
vcol += incr;
|
||||||
MB_PTR_ADV(ptr);
|
ptr = next_ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1620,12 +1602,12 @@ getvcol(
|
|||||||
wp->w_virtcol_first_char = cts.cts_first_char;
|
wp->w_virtcol_first_char = cts.cts_first_char;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (posptr != NULL && cts.cts_ptr >= posptr)
|
char_u *next_ptr = cts.cts_ptr + (*mb_ptr2len)(cts.cts_ptr);
|
||||||
// character at pos->col
|
if (next_ptr - line > pos->col) // character at pos->col
|
||||||
break;
|
break;
|
||||||
|
|
||||||
cts.cts_vcol += incr;
|
cts.cts_vcol += incr;
|
||||||
MB_PTR_ADV(cts.cts_ptr);
|
cts.cts_ptr = next_ptr;
|
||||||
}
|
}
|
||||||
vcol = cts.cts_vcol;
|
vcol = cts.cts_vcol;
|
||||||
ptr = cts.cts_ptr;
|
ptr = cts.cts_ptr;
|
||||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
38,
|
||||||
/**/
|
/**/
|
||||||
37,
|
37,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user