mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.1.0461: too many strlen() calls in drawline.c
Problem: too many strlen() calls in drawline.c Solution: Refactor code to avoid strlen() (John Marriott) closes: #14890 Signed-off-by: John Marriott <basilisk@internode.on.net> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
7577afd5ef
commit
f51ff96532
@ -296,10 +296,9 @@ get_sign_display_info(
|
||||
if (nrcol)
|
||||
{
|
||||
wlv->c_extra = NUL;
|
||||
sprintf((char *)wlv->extra, "%-*c ",
|
||||
number_width(wp), SIGN_BYTE);
|
||||
wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra),
|
||||
"%-*c ", number_width(wp), SIGN_BYTE);
|
||||
wlv->p_extra = wlv->extra;
|
||||
wlv->n_extra = (int)STRLEN(wlv->p_extra);
|
||||
}
|
||||
else
|
||||
wlv->c_extra = SIGN_BYTE;
|
||||
@ -310,10 +309,9 @@ get_sign_display_info(
|
||||
if (nrcol)
|
||||
{
|
||||
wlv->c_extra = NUL;
|
||||
sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
|
||||
MULTISIGN_BYTE);
|
||||
wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra),
|
||||
"%-*c ", number_width(wp), MULTISIGN_BYTE);
|
||||
wlv->p_extra = wlv->extra;
|
||||
wlv->n_extra = (int)STRLEN(wlv->p_extra);
|
||||
}
|
||||
else
|
||||
wlv->c_extra = MULTISIGN_BYTE;
|
||||
@ -332,17 +330,18 @@ get_sign_display_info(
|
||||
if (nrcol)
|
||||
{
|
||||
int width = number_width(wp) - 2;
|
||||
int n;
|
||||
|
||||
for (n = 0; n < width; n++)
|
||||
wlv->extra[n] = ' ';
|
||||
vim_snprintf((char *)wlv->extra + n,
|
||||
sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
|
||||
vim_memset(wlv->extra, ' ', width);
|
||||
wlv->n_extra = width;
|
||||
wlv->n_extra += vim_snprintf((char *)wlv->extra + width,
|
||||
sizeof(wlv->extra) - width, "%s ", wlv->p_extra);
|
||||
wlv->p_extra = wlv->extra;
|
||||
}
|
||||
else
|
||||
wlv->n_extra = (int)STRLEN(wlv->p_extra);
|
||||
|
||||
wlv->c_extra = NUL;
|
||||
wlv->c_final = NUL;
|
||||
wlv->n_extra = (int)STRLEN(wlv->p_extra);
|
||||
}
|
||||
|
||||
if (use_cursor_line_highlight(wp, wlv->lnum)
|
||||
@ -417,7 +416,7 @@ handle_lnum_col(
|
||||
}
|
||||
}
|
||||
|
||||
sprintf((char *)wlv->extra, fmt, number_width(wp), num);
|
||||
vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), fmt, number_width(wp), num);
|
||||
if (wp->w_skipcol > 0 && wlv->startrow == 0)
|
||||
for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
|
||||
++wlv->p_extra)
|
||||
@ -621,25 +620,26 @@ textprop_size_after_trunc(
|
||||
{
|
||||
int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
|
||||
? wp->w_width - win_col_off(wp) : added;
|
||||
int len = (int)STRLEN(text);
|
||||
int strsize = 0;
|
||||
int n_used;
|
||||
char_u *p;
|
||||
|
||||
// if the remaining size is to small and 'wrap' is set we wrap anyway and
|
||||
// if the remaining size is too small and 'wrap' is set we wrap anyway and
|
||||
// use the next line
|
||||
if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
|
||||
space += wp->w_width;
|
||||
if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
|
||||
space -= padding;
|
||||
for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
|
||||
|
||||
for (p = text; *p != NUL; p += (*mb_ptr2len)(p))
|
||||
{
|
||||
int clen = ptr2cells(text + n_used);
|
||||
int clen = ptr2cells(p);
|
||||
|
||||
if (strsize + clen > space)
|
||||
break;
|
||||
strsize += clen;
|
||||
}
|
||||
*n_used_ptr = n_used;
|
||||
*n_used_ptr = (int)(p - text);
|
||||
|
||||
return strsize;
|
||||
}
|
||||
|
||||
@ -1807,7 +1807,7 @@ win_line(
|
||||
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
||||
ptr = line + linecol;
|
||||
|
||||
if (len == 0 || (int)wp->w_cursor.col > ptr - line)
|
||||
if (len == 0 || (int)wp->w_cursor.col > linecol)
|
||||
{
|
||||
// no bad word found at line start, don't check until end of a
|
||||
// word
|
||||
@ -2821,15 +2821,16 @@ win_line(
|
||||
// head byte at end of line
|
||||
mb_l = 1;
|
||||
transchar_nonprint(wp->w_buffer, wlv.extra, c);
|
||||
wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// illegal tail byte
|
||||
mb_l = 2;
|
||||
STRCPY(wlv.extra, "XX");
|
||||
wlv.n_extra = 1;
|
||||
}
|
||||
wlv.p_extra = wlv.extra;
|
||||
wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
|
||||
wlv.c_extra = NUL;
|
||||
wlv.c_final = NUL;
|
||||
c = *wlv.p_extra++;
|
||||
@ -3388,11 +3389,16 @@ win_line(
|
||||
|
||||
c = *wlv.p_extra;
|
||||
p = alloc(wlv.n_extra + 1);
|
||||
vim_memset(p, ' ', wlv.n_extra);
|
||||
STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
|
||||
p[wlv.n_extra] = NUL;
|
||||
vim_free(wlv.p_extra_free);
|
||||
wlv.p_extra_free = wlv.p_extra = p;
|
||||
if (p == NULL)
|
||||
wlv.n_extra = 0;
|
||||
else
|
||||
{
|
||||
vim_memset(p, ' ', wlv.n_extra);
|
||||
STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
|
||||
p[wlv.n_extra] = NUL;
|
||||
vim_free(wlv.p_extra_free);
|
||||
wlv.p_extra_free = wlv.p_extra = p;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -4251,7 +4257,7 @@ win_line(
|
||||
if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
|
||||
{
|
||||
// do not output more of the line, only the "below" prop
|
||||
ptr += STRLEN(ptr);
|
||||
ptr = line + (size_t)ml_get_buf_len(wp->w_buffer, lnum);
|
||||
# ifdef FEAT_LINEBREAK
|
||||
wlv.dont_use_showbreak = TRUE;
|
||||
# endif
|
||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
461,
|
||||
/**/
|
||||
460,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user