gui: Speed up add_spaces().
authorAndre Noll <maan@systemlinux.org>
Mon, 25 Mar 2013 19:08:12 +0000 (19:08 +0000)
committerAndre Noll <maan@systemlinux.org>
Thu, 2 May 2013 17:56:08 +0000 (19:56 +0200)
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

diff --git a/gui.c b/gui.c
index a34f27de5e40cb0adbb2d652d18586c955d88a90..6e44b09d37cc574846f1de0a4d325e586c69dad0 100644 (file)
--- 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);
        }
 }