[Spice-devel] [PATCH spice-common 2/3] log: Optimise glib_debug_level check

Pavel Grunt pgrunt at redhat.com
Wed May 31 09:41:47 UTC 2017


On Wed, 2017-05-31 at 08:53 +0100, Frediano Ziglio wrote:
> Use INT_MAX for invalid value to remove a test in code.
Does not need limits.h ? I'd go for G_MAXINT, the file already has the
 glib header.

Pavel

(yeah, I know it is defined as INT_MAX)

> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  common/log.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/common/log.c b/common/log.c
> index 014b416..dae955a 100644
> --- a/common/log.c
> +++ b/common/log.c
> @@ -30,7 +30,7 @@
>  #include "log.h"
>  #include "backtrace.h"
>  
> -static int glib_debug_level = 0;
> +static int glib_debug_level = INT_MAX;
>  static int abort_level = -1;
>  
>  #ifndef SPICE_ABORT_LEVEL_DEFAULT
> @@ -58,7 +58,7 @@ static GLogLevelFlags
> spice_log_level_to_glib(SpiceLogLevel level)
>  
>  static void spice_log_set_debug_level(void)
>  {
> -    if (glib_debug_level == 0) {
> +    if (glib_debug_level == INT_MAX) {
>          const char *debug_str = g_getenv("SPICE_DEBUG_LEVEL");
>          if (debug_str != NULL) {
>              int debug_level;
> @@ -121,9 +121,8 @@ static void spice_logger(const gchar
> *log_domain,
>                           const gchar *message,
>                           gpointer user_data G_GNUC_UNUSED)
>  {
> -    if (glib_debug_level != 0) {
> -        if ((log_level & G_LOG_LEVEL_MASK) > glib_debug_level)
> -            return; // do not print anything
> +    if ((log_level & G_LOG_LEVEL_MASK) > glib_debug_level) {
> +        return; // do not print anything
>      }
>      g_log_default_handler(log_domain, log_level, message, NULL);
>  }


More information about the Spice-devel mailing list