tweaks: slightly optimize an allocation in display_string()

Instead of allocating enough space to convert the entire passed string,
just allocate space for converting the part that will be converted --
that is: starting from start_index.  This still allocates far too much
(if the passed string is very long and its tail part won't fit on the
screen), but it's better than before.
master
David Lawrence Ramsey 2017-02-20 21:07:35 -06:00 committed by Benno Schulenberg
parent 1d3f3a6e25
commit f1d214c0ef
1 changed files with 3 additions and 3 deletions

View File

@ -1823,15 +1823,15 @@ char *display_string(const char *buf, size_t start_col, size_t span,
assert(column <= start_col); assert(column <= start_col);
/* Allocate enough space to hold the entire converted buffer. */
converted = charalloc(strlen(buf) * (mb_cur_max() + tabsize) + 1);
index = 0; index = 0;
#ifdef USING_OLD_NCURSES #ifdef USING_OLD_NCURSES
seen_wide = FALSE; seen_wide = FALSE;
#endif #endif
buf += start_index; buf += start_index;
/* Allocate enough space for converting the relevant part of the line. */
converted = charalloc(strlen(buf) * (mb_cur_max() + tabsize) + 1);
/* If the first character starts before the left edge, or would be /* If the first character starts before the left edge, or would be
* overwritten by a "$" token, then show spaces instead. */ * overwritten by a "$" token, then show spaces instead. */
if (*buf != '\0' && *buf != '\t' && (column < start_col || if (*buf != '\0' && *buf != '\t' && (column < start_col ||