From ca566ad554a80c8d8d24cdde9daf94e9e9496569 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Wed, 4 Oct 2017 00:00:00 -0500 Subject: [PATCH] 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 --- top/top.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/top/top.c b/top/top.c index c6d38cf3..bd56ca74 100644 --- a/top/top.c +++ b/top/top.c @@ -1449,9 +1449,7 @@ static inline const char *make_str_utf8 (const char *str, int width, int justr, static char buf[SCREENMAX]; int delta = utf8_delta(str); - if (width >= (int)strlen(str) - delta) - snprintf(buf, sizeof(buf), "%s", str); - else { + if (width + delta <= snprintf(buf, sizeof(buf), "%s", str)) { snprintf(buf, sizeof(buf), "%.*s", utf8_embody(str, width - 1), str); delta = utf8_delta(buf); buf[width + delta - 1] = COLPLUSCH;