From e90c6c0a4d28a3f39e671c74ffe7c3de64650aa7 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 25 Mar 2013 19:08:12 +0000 Subject: [PATCH 1/1] 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. --- gui.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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); } } -- 2.39.2