From c492f4aec21b2a70b1832ceb3f64a2692d0b92e2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 15 May 2022 22:12:58 -0400 Subject: [PATCH] gtype: small optimization These warnings are never seen at runtime, so they are evidently very unlikely. Tell the compiler that. --- gobject/gtype.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gobject/gtype.c b/gobject/gtype.c index cf213b760..c08f11345 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -1858,13 +1858,13 @@ g_type_create_instance (GType type) guint i; node = lookup_type_node_I (type); - if (!node || !node->is_instantiatable) + if (G_UNLIKELY (!node || !node->is_instantiatable)) { g_error ("cannot create new instance of invalid (non-instantiatable) type '%s'", type_descriptive_name_I (type)); } /* G_TYPE_IS_ABSTRACT() is an external call: _U */ - if (!node->mutatable_check_cache && G_TYPE_IS_ABSTRACT (type)) + if (G_UNLIKELY (!node->mutatable_check_cache && G_TYPE_IS_ABSTRACT (type))) { g_error ("cannot create instance of abstract (non-instantiatable) type '%s'", type_descriptive_name_I (type)); @@ -1893,7 +1893,7 @@ g_type_create_instance (GType type) ivar_size = node->data->instance.instance_size; #ifdef ENABLE_VALGRIND - if (private_size && RUNNING_ON_VALGRIND) + if (G_UNLIKELY (private_size && RUNNING_ON_VALGRIND)) { private_size += ALIGN_STRUCT (1); @@ -1963,14 +1963,14 @@ g_type_free_instance (GTypeInstance *instance) class = instance->g_class; node = lookup_type_node_I (class->g_type); - if (!node || !node->is_instantiatable || !node->data || node->data->class.class != (gpointer) class) + if (G_UNLIKELY (!node || !node->is_instantiatable || !node->data || node->data->class.class != (gpointer) class)) { g_warning ("cannot free instance of invalid (non-instantiatable) type '%s'", type_descriptive_name_I (class->g_type)); return; } /* G_TYPE_IS_ABSTRACT() is an external call: _U */ - if (!node->mutatable_check_cache && G_TYPE_IS_ABSTRACT (NODE_TYPE (node))) + if (G_UNLIKELY (!node->mutatable_check_cache && G_TYPE_IS_ABSTRACT (NODE_TYPE (node)))) { g_warning ("cannot free instance of abstract (non-instantiatable) type '%s'", NODE_NAME (node)); @@ -1990,7 +1990,7 @@ g_type_free_instance (GTypeInstance *instance) /* See comment in g_type_create_instance() about what's going on here. * We're basically unwinding what we put into motion there. */ - if (private_size && RUNNING_ON_VALGRIND) + if (G_UNLIKELY (private_size && RUNNING_ON_VALGRIND)) { private_size += ALIGN_STRUCT (1); allocated -= ALIGN_STRUCT (1);