debug: Use G_UNLIKELY in the tests
authorDamien Lespiau <damien.lespiau@intel.com>
Mon, 3 May 2010 18:41:17 +0000 (20:41 +0200)
committerDamien Lespiau <damien.lespiau@intel.com>
Tue, 4 May 2010 16:01:14 +0000 (17:01 +0100)
Debugging code is not meant to be run in the nominal code path. Use
G_UNLIKELY to be reduce the number of bubbles in the instruction
pipeline.

Took the opportunity to re-indent the macros.

clutter/clutter-debug.h
clutter/cogl/cogl/cogl-debug.h

index 554eb8e..d8fc63d 100644 (file)
@@ -39,39 +39,39 @@ typedef enum {
 #ifdef CLUTTER_ENABLE_DEBUG
 
 #ifdef __GNUC__
-#define CLUTTER_NOTE(type,x,a...)               G_STMT_START {  \
-        if (clutter_debug_flags & CLUTTER_DEBUG_##type)         \
-          { g_message ("[" #type "] " G_STRLOC ": " x, ##a); }  \
-                                                } G_STMT_END
-
-#define CLUTTER_TIMESTAMP(type,x,a...)             G_STMT_START {  \
-        if (clutter_debug_flags & CLUTTER_DEBUG_##type)            \
-          { g_message ("[" #type "]" " %li:"  G_STRLOC ": "        \
-                       x, clutter_get_timestamp(), ##a); }         \
-                                                   } G_STMT_END
+#define CLUTTER_NOTE(type,x,a...)                     G_STMT_START { \
+        if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_##type)) \
+          { g_message ("[" #type "] " G_STRLOC ": " x, ##a); }       \
+                                                      } G_STMT_END
+
+#define CLUTTER_TIMESTAMP(type,x,a...)                G_STMT_START { \
+        if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_##type)) \
+          { g_message ("[" #type "]" " %li:"  G_STRLOC ": "          \
+                       x, clutter_get_timestamp(), ##a); }           \
+                                                      } G_STMT_END
 #else
 /* Try the C99 version; unfortunately, this does not allow us to pass
  * empty arguments to the macro, which means we have to
  * do an intemediate printf.
  */
-#define CLUTTER_NOTE(type,...)               G_STMT_START {  \
-        if (clutter_debug_flags & CLUTTER_DEBUG_##type)      \
-       {                                                    \
-         gchar * _fmt = g_strdup_printf (__VA_ARGS__);      \
-          g_message ("[" #type "] " G_STRLOC ": %s",_fmt);   \
-          g_free (_fmt);                                     \
-       }                                                    \
-                                                } G_STMT_END
-
-#define CLUTTER_TIMESTAMP(type,...)             G_STMT_START {  \
-        if (clutter_debug_flags & CLUTTER_DEBUG_##type)         \
-       {                                                       \
-         gchar * _fmt = g_strdup_printf (__VA_ARGS__);         \
-          g_message ("[" #type "]" " %li:"  G_STRLOC ": %s",    \
-                       clutter_get_timestamp(), _fmt);          \
-          g_free (_fmt);                                        \
-       }                                                       \
-                                                   } G_STMT_END
+#define CLUTTER_NOTE(type,...)                        G_STMT_START { \
+        if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_##type)) \
+          {                                                          \
+            gchar * _fmt = g_strdup_printf (__VA_ARGS__);            \
+            g_message ("[" #type "] " G_STRLOC ": %s",_fmt);         \
+            g_free (_fmt);                                           \
+          }                                                          \
+                                                      } G_STMT_END
+
+#define CLUTTER_TIMESTAMP(type,...)                   G_STMT_START { \
+        if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_##type)) \
+          {                                                          \
+            gchar * _fmt = g_strdup_printf (__VA_ARGS__);            \
+            g_message ("[" #type "]" " %li:"  G_STRLOC ": %s",       \
+                       clutter_get_timestamp(), _fmt);               \
+            g_free (_fmt);                                           \
+          }                                                          \
+                                                      } G_STMT_END
 #endif
 
 #define CLUTTER_MARK()      CLUTTER_NOTE(MISC, "== mark ==")
index c3e1973..2537b26 100644 (file)
@@ -52,18 +52,18 @@ typedef enum {
 #ifdef COGL_ENABLE_DEBUG
 
 #ifdef __GNUC__
-#define COGL_NOTE(type,x,a...)                  G_STMT_START {  \
-        if (cogl_debug_flags & COGL_DEBUG_##type) {             \
-          g_message ("[" #type "] " G_STRLOC ": " x, ##a);      \
-        }                                       } G_STMT_END
+#define COGL_NOTE(type,x,a...)                      G_STMT_START { \
+        if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_##type)) {   \
+          g_message ("[" #type "] " G_STRLOC ": " x, ##a);         \
+        }                                           } G_STMT_END
 
 #else
-#define COGL_NOTE(type,...)                     G_STMT_START {  \
-        if (cogl_debug_flags & COGL_DEBUG_##type) {             \
-          char *_fmt = g_strdup_printf (__VA_ARGS__);          \
-          g_message ("[" #type "] " G_STRLOC ": %s", _fmt);     \
-          g_free (_fmt);                                        \
-        }                                       } G_STMT_END
+#define COGL_NOTE(type,...)                         G_STMT_START { \
+        if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_##type)) {   \
+          char *_fmt = g_strdup_printf (__VA_ARGS__);              \
+          g_message ("[" #type "] " G_STRLOC ": %s", _fmt);        \
+          g_free (_fmt);                                           \
+        }                                           } G_STMT_END
 
 #endif /* __GNUC__ */