mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-20 15:48:54 +02:00
gtype: Speed up type checking for final types
Store the final flag directly in the TypeNode, so we can get it cheaply, and use it to speed up g_type_instance_is_a for final types.
This commit is contained in:
committed by
Marco Trevisan (Treviño)
parent
6a0591f06c
commit
a31b042dfc
@@ -233,7 +233,9 @@ struct _TypeNode
|
|||||||
guint n_prerequisites : 9;
|
guint n_prerequisites : 9;
|
||||||
guint is_classed : 1;
|
guint is_classed : 1;
|
||||||
guint is_instantiatable : 1;
|
guint is_instantiatable : 1;
|
||||||
|
guint is_final : 1;
|
||||||
guint mutatable_check_cache : 1; /* combines some common path checks */
|
guint mutatable_check_cache : 1; /* combines some common path checks */
|
||||||
|
|
||||||
GType *children; /* writable with lock */
|
GType *children; /* writable with lock */
|
||||||
TypeData *data;
|
TypeData *data;
|
||||||
GQuark qname;
|
GQuark qname;
|
||||||
@@ -3909,6 +3911,8 @@ type_add_flags_W (TypeNode *node,
|
|||||||
dflags = GPOINTER_TO_UINT (type_get_qdata_L (node, static_quark_type_flags));
|
dflags = GPOINTER_TO_UINT (type_get_qdata_L (node, static_quark_type_flags));
|
||||||
dflags |= flags;
|
dflags |= flags;
|
||||||
type_set_qdata_W (node, static_quark_type_flags, GUINT_TO_POINTER (dflags));
|
type_set_qdata_W (node, static_quark_type_flags, GUINT_TO_POINTER (dflags));
|
||||||
|
|
||||||
|
node->is_final = (flags & G_TYPE_FLAG_FINAL) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -4134,9 +4138,12 @@ g_type_check_instance_is_a (GTypeInstance *type_instance,
|
|||||||
|
|
||||||
if (!type_instance || !type_instance->g_class)
|
if (!type_instance || !type_instance->g_class)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
node = lookup_type_node_I (type_instance->g_class->g_type);
|
|
||||||
iface = lookup_type_node_I (iface_type);
|
iface = lookup_type_node_I (iface_type);
|
||||||
|
if (iface->is_final)
|
||||||
|
return type_instance->g_class->g_type == iface_type;
|
||||||
|
|
||||||
|
node = lookup_type_node_I (type_instance->g_class->g_type);
|
||||||
check = node && node->is_instantiatable && iface && type_node_conforms_to_U (node, iface, TRUE, FALSE);
|
check = node && node->is_instantiatable && iface && type_node_conforms_to_U (node, iface, TRUE, FALSE);
|
||||||
|
|
||||||
return check;
|
return check;
|
||||||
|
Reference in New Issue
Block a user