Commit dc645ce3 authored by Matthias Clasen's avatar Matthias Clasen

Use G_LIKELY. (#69022)

	* 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)

	* glib/tmpl/macros_misc.sgml: Document G_LIKELY, G_UNLIKELY.

	* glib/glib-sections.txt: Add G_LIKELY, G_UNLIKELY.
parent 17cff032
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):
......
......@@ -296,6 +296,10 @@ G_GNUC_FUNCTION
G_GNUC_PRETTY_FUNCTION
G_GNUC_NO_INSTRUMENT
<SUBSECTION>
G_LIKELY
G_UNLIKELY
<SUBSECTION>
G_STRLOC
......
......@@ -237,6 +237,32 @@ See the GNU C documentation for details.
<!-- ##### 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.
......
......@@ -197,4 +197,19 @@
#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__ */
......@@ -29,6 +29,7 @@
#include <stdarg.h>
#include <glib/gtypes.h>
#include <glib/gmacros.h>
/* Suppress warnings when GCC is in -pedantic mode and not -std=c99
*/
......@@ -252,7 +253,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func);
#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, \
......@@ -265,7 +266,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func);
}; }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, \
......@@ -298,7 +299,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func);
#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, \
......@@ -310,7 +311,7 @@ GPrintFunc g_set_printerr_handler (GPrintFunc func);
}; }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, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment