From: Jim Warner Date: Wed, 4 Oct 2017 05:00:00 +0000 (-0500) Subject: top: make that 'make_str_utf8' function more efficient X-Git-Tag: v3.3.13rc1~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=abde5d7d5e78a413a9f1a62ed3d6cc0e936bcf07;p=procps-ng 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 --- 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;