[glib/gobject-speedups: 95/103] gtype: Speed up g_type_is_a




commit db8cccf8b458f52089d45b03560121c92ed365b6
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.

 gobject/gtype.c | 4 ++--
 gobject/gtype.h | 6 +++++-
 2 files changed, 7 insertions(+), 3 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..3c214a59c8 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -725,8 +725,12 @@ guint                 g_type_depth                   (GType            type);
 GLIB_AVAILABLE_IN_ALL
 GType                 g_type_next_base               (GType            leaf_type,
                                                      GType            root_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
-gboolean              g_type_is_a                    (GType            type,
+gboolean              (g_type_is_a)                  (GType            type,
                                                      GType            is_a_type);
 GLIB_AVAILABLE_IN_ALL
 gpointer              g_type_class_ref               (GType            type);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]