From: Andre Noll Date: Mon, 25 Mar 2013 19:08:12 +0000 (+0000) Subject: gui: Speed up add_spaces(). X-Git-Tag: v0.4.13~33^2~7 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=e90c6c0a4d28a3f39e671c74ffe7c3de64650aa7 gui: Speed up add_spaces(). The calls to waddstr() in this function showed up in profiles. So print the full string at once instead of calling waddstr() for each character. --- diff --git a/gui.c b/gui.c index a34f27de..6e44b09d 100644 --- a/gui.c +++ b/gui.c @@ -287,14 +287,20 @@ static char *configfile_exists(void) return file_exists(tmp)? tmp: NULL; } -/* - * print num spaces to curses window - */ +/* Print given number of spaces to curses window. */ static void add_spaces(WINDOW* win, unsigned int num) { - while (num > 0) { - num--; - waddstr(win, " "); + char space[] = " "; + unsigned sz = sizeof(space); + + while (num >= sz) { + waddstr(win, space); + num -= sz; + } + if (num > 0) { + assert(num < sz); + space[num] = '\0'; + waddstr(win, space); } }