[Spice-devel] [PATCH spice-gtk 06/10] util: avoid calling getenv for every SPICE_DEBUG

Marc-André Lureau marcandre.lureau at gmail.com
Sun Sep 8 11:59:29 PDT 2013


From: Marc-André Lureau <marcandre.lureau at gmail.com>

That doesn't seem to really improve performance so much,
but that' s what we should do probably.
---
 gtk/spice-util.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/gtk/spice-util.c b/gtk/spice-util.c
index e02fc4d..4372f28 100644
--- a/gtk/spice-util.c
+++ b/gtk/spice-util.c
@@ -39,7 +39,7 @@
  * Various functions for debugging and informational purposes.
  */
 
-static gboolean debugFlag = FALSE;
+static GOnce debug_once = G_ONCE_INIT;
 
 /**
  * spice_util_set_debug:
@@ -61,12 +61,19 @@ void spice_util_set_debug(gboolean enabled)
         }
     }
 #endif
-    debugFlag = enabled;
+    debug_once.retval = GINT_TO_POINTER(enabled);
+}
+
+static gpointer getenv_debug(gpointer data)
+{
+    return GINT_TO_POINTER(g_getenv("SPICE_DEBUG") != NULL);
 }
 
 gboolean spice_util_get_debug(void)
 {
-    return debugFlag || g_getenv("SPICE_DEBUG") != NULL;
+    g_once(&debug_once, getenv_debug, NULL);
+
+    return GPOINTER_TO_INT(debug_once.retval);
 }
 
 /**
-- 
1.8.3.1



More information about the Spice-devel mailing list