summaryrefslogtreecommitdiff
path: root/gobject
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2022-11-29 21:36:48 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2022-12-06 01:22:34 +0100
commitc0360f626cecd0b5612373d8e4989405e3168db8 (patch)
tree8a17b7d348e0157391621c05c358b0afbec027ea /gobject
parent65303537b0ed0add418da206024f6d87429c788a (diff)
downloadglib-c0360f626cecd0b5612373d8e4989405e3168db8.tar.gz
gobject: Read the toggle reference state only after we've update the references
We were reading if an object has toggle references even if this was not really relevant for the current object state, as we only need to notify when going from 2 to 1 references, so first ensure that this is the case and then check if we have toggle references enabled in the object. This is a micro-optimization, for the way flags are defined, but still an operation we can avoid in most cases.
Diffstat (limited to 'gobject')
-rw-r--r--gobject/gobject.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 43d337d1b..6f0149d12 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -3794,7 +3794,6 @@ g_object_unref (gpointer _object)
while (old_ref > 1)
{
/* valid if last 2 refs are owned by this call to unref and the toggle_ref */
- gboolean has_toggle_ref = OBJECT_HAS_TOGGLE_REF (object);
if (!g_atomic_int_compare_and_exchange_full ((int *)&object->ref_count,
old_ref, old_ref - 1,
@@ -3804,8 +3803,11 @@ g_object_unref (gpointer _object)
TRACE (GOBJECT_OBJECT_UNREF(object,G_TYPE_FROM_INSTANCE(object),old_ref));
/* if we went from 2->1 we need to notify toggle refs if any */
- if (old_ref == 2 && has_toggle_ref) /* The last ref being held in this case is owned by the toggle_ref */
- toggle_refs_notify (object, TRUE);
+ if (old_ref == 2 && OBJECT_HAS_TOGGLE_REF (object))
+ {
+ /* The last ref being held in this case is owned by the toggle_ref */
+ toggle_refs_notify (object, TRUE);
+ }
return;
}