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.
This commit is contained in:
Matthias Clasen 2022-05-19 21:06:18 -04:00
parent c492f4aec2
commit 22f51b87a2
2 changed files with 6 additions and 2 deletions

View File

@ -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;

View File

@ -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