+2002-11-20 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gmessages.h (g_return_if_fail):
+ (g_return_val_if_fail): Use G_LIKELY. (#69022)
+
+ * glib/gmacros.h (G_LIKELY):
+ (G_UNLIKELY): New macros for hinting the compiler about the
+ expected result of expressions. For gcc 3.x, define these
+ using __builtin_expect. (#69022)
+
Tue Nov 19 14:38:18 2002 Owen Taylor <otaylor@redhat.com>
* glib/gstrfuncs.c (g_ascii_strtoull): Fix
+2002-11-20 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gmessages.h (g_return_if_fail):
+ (g_return_val_if_fail): Use G_LIKELY. (#69022)
+
+ * glib/gmacros.h (G_LIKELY):
+ (G_UNLIKELY): New macros for hinting the compiler about the
+ expected result of expressions. For gcc 3.x, define these
+ using __builtin_expect. (#69022)
+
Tue Nov 19 14:38:18 2002 Owen Taylor <otaylor@redhat.com>
* glib/gstrfuncs.c (g_ascii_strtoull): Fix
+2002-11-20 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gmessages.h (g_return_if_fail):
+ (g_return_val_if_fail): Use G_LIKELY. (#69022)
+
+ * glib/gmacros.h (G_LIKELY):
+ (G_UNLIKELY): New macros for hinting the compiler about the
+ expected result of expressions. For gcc 3.x, define these
+ using __builtin_expect. (#69022)
+
Tue Nov 19 14:38:18 2002 Owen Taylor <otaylor@redhat.com>
* glib/gstrfuncs.c (g_ascii_strtoull): Fix
+2002-11-20 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gmessages.h (g_return_if_fail):
+ (g_return_val_if_fail): Use G_LIKELY. (#69022)
+
+ * glib/gmacros.h (G_LIKELY):
+ (G_UNLIKELY): New macros for hinting the compiler about the
+ expected result of expressions. For gcc 3.x, define these
+ using __builtin_expect. (#69022)
+
Tue Nov 19 14:38:18 2002 Owen Taylor <otaylor@redhat.com>
* glib/gstrfuncs.c (g_ascii_strtoull): Fix
+2002-11-20 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gmessages.h (g_return_if_fail):
+ (g_return_val_if_fail): Use G_LIKELY. (#69022)
+
+ * glib/gmacros.h (G_LIKELY):
+ (G_UNLIKELY): New macros for hinting the compiler about the
+ expected result of expressions. For gcc 3.x, define these
+ using __builtin_expect. (#69022)
+
Tue Nov 19 14:38:18 2002 Owen Taylor <otaylor@redhat.com>
* glib/gstrfuncs.c (g_ascii_strtoull): Fix
+2002-11-20 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gmessages.h (g_return_if_fail):
+ (g_return_val_if_fail): Use G_LIKELY. (#69022)
+
+ * glib/gmacros.h (G_LIKELY):
+ (G_UNLIKELY): New macros for hinting the compiler about the
+ expected result of expressions. For gcc 3.x, define these
+ using __builtin_expect. (#69022)
+
Tue Nov 19 14:38:18 2002 Owen Taylor <otaylor@redhat.com>
* glib/gstrfuncs.c (g_ascii_strtoull): Fix
+2002-11-20 Matthias Clasen <maclas@gmx.de>
+
+ * glib/gmessages.h (g_return_if_fail):
+ (g_return_val_if_fail): Use G_LIKELY. (#69022)
+
+ * glib/gmacros.h (G_LIKELY):
+ (G_UNLIKELY): New macros for hinting the compiler about the
+ expected result of expressions. For gcc 3.x, define these
+ using __builtin_expect. (#69022)
+
Tue Nov 19 14:38:18 2002 Owen Taylor <otaylor@redhat.com>
* glib/gstrfuncs.c (g_ascii_strtoull): Fix
+2002-11-20 Matthias Clasen <maclas@gmx.de>
+
+ * glib/tmpl/macros_misc.sgml: Document G_LIKELY, G_UNLIKELY.
+
+ * glib/glib-sections.txt: Add G_LIKELY, G_UNLIKELY.
+
2002-10-20 Matthias Clasen <maclas@gmx.de>
* gobject/Makefile.am (SCANOBJ_FILES):
G_GNUC_NO_INSTRUMENT
<SUBSECTION>
+G_LIKELY
+G_UNLIKELY
+
+<SUBSECTION>
G_STRLOC
<SUBSECTION>
+<!-- ##### MACRO G_LIKELY ##### -->
+<para>
+Hints the compiler that the expression is likely to evaluate to a true
+value. The compiler may use this information for optimizations.
+</para>
+<informalexample><programlisting>
+if (G_LIKELY (random () != 1))
+ g_print ("not one");
+</programlisting></informalexample>
+
+@expr: the expression
+
+
+<!-- ##### MACRO G_UNLIKELY ##### -->
+<para>
+Hints the compiler that the expression is unlikely to evaluate to a true
+value. The compiler may use this information for optimizations.
+</para>
+<informalexample><programlisting>
+if (G_UNLIKELY (random () == 1))
+ g_print ("a random one");
+</programlisting></informalexample>
+
+@expr: the expression
+
+
<!-- ##### MACRO G_STRLOC ##### -->
<para>
Expands to a string identifying the current code position.
#define G_CONST_RETURN const
#endif
+/*
+ * The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
+ * the compiler about the expected result of an expression. Some compilers
+ * can use this information for optimizations.
+ */
+#if defined(__GNUC__) && (__GNUC__ > 2)
+#define G_LIKELY(expr) __builtin_expect (!!(expr), 1)
+#define G_UNLIKELY(expr) __builtin_expect (!!(expr), 0)
+#else
+#define G_LIKELY(expr) expr
+#define G_UNLIKELY(expr) expr
+#endif
+
#endif /* __G_MACROS_H__ */
+
+
#include <stdarg.h>
#include <glib/gtypes.h>
+#include <glib/gmacros.h>
/* Suppress warnings when GCC is in -pedantic mode and not -std=c99
*/
#ifdef __GNUC__
#define g_return_if_fail(expr) G_STMT_START{ \
- if (expr) { } else \
+ if (G_LIKELY (expr)) { } else \
{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
}; }G_STMT_END
#define g_return_val_if_fail(expr,val) G_STMT_START{ \
- if (expr) { } else \
+ if (G_LIKELY (expr)) { } else \
{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
#else /* !__GNUC__ */
#define g_return_if_fail(expr) G_STMT_START{ \
- if (expr) { } else \
+ if (G_LIKELY (expr)) { } else \
{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
}; }G_STMT_END
#define g_return_val_if_fail(expr, val) G_STMT_START{ \
- if (expr) { } else \
+ if (G_LIKELY (expr)) { } else \
{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \