[glib/final-type-check-2] gtype: Speed up type checking for final types
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/final-type-check-2] gtype: Speed up type checking for final types
- Date: Mon, 6 Jun 2022 21:28:10 +0000 (UTC)
commit 6a1ab05f9989040e107ced3df4f116d90f32df70
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jun 6 17:26:38 2022 -0400
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.
gobject/gtype.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gobject/gtype.c b/gobject/gtype.c
index ded0acee28..dbbf98d408 100644
--- a/gobject/gtype.c
+++ b/gobject/gtype.c
@@ -232,6 +232,8 @@ struct _TypeNode
guint is_classed : 1;
guint is_instantiatable : 1;
guint mutatable_check_cache : 1; /* combines some common path checks */
+ guint is_final : 1;
+
GType *children; /* writable with lock */
TypeData *data;
GQuark qname;
@@ -3850,6 +3852,8 @@ type_add_flags_W (TypeNode *node,
dflags = GPOINTER_TO_UINT (type_get_qdata_L (node, static_quark_type_flags));
dflags |= flags;
type_set_qdata_W (node, static_quark_type_flags, GUINT_TO_POINTER (dflags));
+
+ node->is_final = (flags & G_TYPE_FLAG_FINAL) != 0;
}
/**
@@ -4075,9 +4079,12 @@ g_type_check_instance_is_a (GTypeInstance *type_instance,
if (!type_instance || !type_instance->g_class)
return FALSE;
-
- node = lookup_type_node_I (type_instance->g_class->g_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);
return check;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]