[glib/gtype-speedups: 1/2] gtype: Speed up g_type_is_a
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/gtype-speedups: 1/2] gtype: Speed up g_type_is_a
- Date: Fri, 20 May 2022 13:08:17 +0000 (UTC)
commit 22f51b87a28b308be4bd0d462b7a3a0e9e7d1790
Author: Matthias Clasen <mclasen redhat com>
Date: Thu May 19 21:06:18 2022 -0400
gtype: Speed up g_type_is_a
As noticed by Christian Hergert: We can reduce
some overhead by checking for exact type
equality first. According to Christian, around
3% of g_type_is_a calls are exact equalities.
gobject/gtype.c | 4 ++--
gobject/gtype.h | 4 ++++
2 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/gobject/gtype.c b/gobject/gtype.c
index c08f11345d..ded0acee28 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -3577,8 +3577,8 @@ type_node_conforms_to_U (TypeNode *node,
* Returns: %TRUE if @type is a @is_a_type
*/
gboolean
-g_type_is_a (GType type,
- GType iface_type)
+(g_type_is_a) (GType type,
+ GType iface_type)
{
TypeNode *node, *iface_node;
gboolean is_a;
diff --git a/gobject/gtype.h b/gobject/gtype.h
index f2620f83bf..66cac1fc58 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -728,6 +728,10 @@ GType g_type_next_base (GType leaf_type
GLIB_AVAILABLE_IN_ALL
gboolean g_type_is_a (GType type,
GType is_a_type);
+
+/* Hoist exact GType comparisons into the caller */
+#define g_type_is_a(a,b) ((a) == (b) || (g_type_is_a) ((a), (b)))
+
GLIB_AVAILABLE_IN_ALL
gpointer g_type_class_ref (GType type);
GLIB_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]