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

Yonit Halperin yhalperi at redhat.com
Mon Sep 9 13:26:57 PDT 2013


ack
On 09/08/2013 02:59 PM, Marc-André Lureau wrote:
> 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);
>   }
>
>   /**
>



More information about the Spice-devel mailing list