top: make that 'make_str_utf8' function more efficient

Upon reflection, there was absolutely no justification
for that call to strlen() which was then followed by a
call to snprintf(). The latter provides this needed #.

[ also make that 'delta' value a little more visible ]
[ instead of hiding it at the end of a its code line ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2017-10-04 00:00:00 -05:00 committed by Craig Small
parent 0154ffb280
commit ca566ad554

View File

@ -1449,9 +1449,7 @@ static inline const char *make_str_utf8 (const char *str, int width, int justr,
static char buf[SCREENMAX]; static char buf[SCREENMAX];
int delta = utf8_delta(str); int delta = utf8_delta(str);
if (width >= (int)strlen(str) - delta) if (width + delta <= snprintf(buf, sizeof(buf), "%s", str)) {
snprintf(buf, sizeof(buf), "%s", str);
else {
snprintf(buf, sizeof(buf), "%.*s", utf8_embody(str, width - 1), str); snprintf(buf, sizeof(buf), "%.*s", utf8_embody(str, width - 1), str);
delta = utf8_delta(buf); delta = utf8_delta(buf);
buf[width + delta - 1] = COLPLUSCH; buf[width + delta - 1] = COLPLUSCH;