From abde5d7d5e78a413a9f1a62ed3d6cc0e936bcf07 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 bf52150a..49f3732e 100644 --- a/top/top.c +++ b/top/top.c @@ -1636,9 +1636,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; -- 2.40.0