From: Sami Kerola Date: Fri, 2 Sep 2016 21:05:53 +0000 (+0100) Subject: performance: use fewer printw() calls to center text X-Git-Tag: v0.88~26^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5edb9708a93b812e1ce763f9a6d64495567cb8b6;p=thirdparty%2Fmtr.git performance: use fewer printw() calls to center text Avoid printing white space one by one when variable length print out of nothing can do the same thing. Signed-off-by: Sami Kerola --- diff --git a/curses.c b/curses.c index 34fdafb..c4b7980 100644 --- a/curses.c +++ b/curses.c @@ -70,14 +70,12 @@ static void pwcenter(char *str) { int maxx; - int cx; + size_t cx; int __unused_int UNUSED; getmaxyx(stdscr, __unused_int, maxx); - cx = (signed)(maxx - strlen(str)) / 2; - while(cx-- > 0) - printw(" "); - printw(str); + cx = (size_t)(maxx - strlen(str)) / 2; + printw("%*s%s", cx, "", str); }