0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.1.0997: too many strlen() calls in drawscreen.c

Problem:  too many strlen() calls in drawscreen.c
Solution: refactor drawscreen.c and remove calls to strlen(),
          make get_keymap_str() (in screen.c) return string length
          instead of TRUE/FALSE (John Marriott).

Signed-off-by: John Marriott <basilisk@internode.on.net>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
John Marriott
2025-01-08 20:10:59 +01:00
committed by Christian Brabandt
parent 8ab1819df6
commit a21240b97d
5 changed files with 125 additions and 123 deletions

View File

@@ -3914,7 +3914,7 @@ fileinfo(
n);
validate_virtcol();
len = STRLEN(buffer);
col_print((char_u *)buffer + len, IOSIZE - len,
(void)col_print((char_u *)buffer + len, IOSIZE - len,
(int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1);
}
@@ -3946,7 +3946,7 @@ fileinfo(
vim_free(buffer);
}
void
int
col_print(
char_u *buf,
size_t buflen,
@@ -3954,9 +3954,9 @@ col_print(
int vcol)
{
if (col == vcol)
vim_snprintf((char *)buf, buflen, "%d", col);
else
vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol);
return vim_snprintf((char *)buf, buflen, "%d", col);
return vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol);
}
static char_u *lasttitle = NULL;
@@ -4820,7 +4820,7 @@ build_stl_str_hl(
case STL_ALTPERCENT:
str = buf_tmp;
get_rel_pos(wp, str, TMPLEN);
(void)get_rel_pos(wp, str, TMPLEN);
break;
case STL_SHOWCMD:
@@ -4837,7 +4837,7 @@ build_stl_str_hl(
case STL_KEYMAP:
fillable = FALSE;
if (get_keymap_str(wp, (char_u *)"<%s>", buf_tmp, TMPLEN))
if (get_keymap_str(wp, (char_u *)"<%s>", buf_tmp, TMPLEN) > 0)
str = buf_tmp;
break;
case STL_PAGENUM:
@@ -5271,7 +5271,7 @@ build_stl_str_hl(
* Get relative cursor position in window into "buf[buflen]", in the localized
* percentage form like %99, 99%; using "Top", "Bot" or "All" when appropriate.
*/
void
int
get_rel_pos(
win_T *wp,
char_u *buf,
@@ -5279,9 +5279,10 @@ get_rel_pos(
{
long above; // number of lines above window
long below; // number of lines below window
int len;
if (buflen < 3) // need at least 3 chars for writing
return;
return 0;
above = wp->w_topline - 1;
#ifdef FEAT_DIFF
above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill;
@@ -5292,28 +5293,27 @@ get_rel_pos(
#endif
below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1;
if (below <= 0)
vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")),
(size_t)(buflen - 1));
len = vim_snprintf((char *)buf, buflen, "%s", (above == 0) ? _("All") : _("Bot"));
else if (above <= 0)
vim_strncpy(buf, (char_u *)_("Top"), (size_t)(buflen - 1));
len = vim_snprintf((char *)buf, buflen, "%s", _("Top"));
else
{
int perc = (above > 1000000L)
? (int)(above / ((above + below) / 100L))
: (int)(above * 100L / (above + below));
? (int)(above / ((above + below) / 100L))
: (int)(above * 100L / (above + below));
char *p = (char *)buf;
size_t l = buflen;
if (perc < 10)
{
// prepend one space
buf[0] = ' ';
++p;
--l;
}
// localized percentage value
vim_snprintf(p, l, _("%d%%"), perc);
len = vim_snprintf((char *)buf, buflen, _("%s%d%%"), (perc < 10) ? " " : "", perc);
}
if (len < 0)
{
buf[0] = NUL;
len = 0;
}
else if (len > buflen - 1)
len = buflen - 1;
return len;
}
/*