GVariant: avoid locking in a common case

Avoid acquiring the lock on the instance on the case of deserialising a
child.  We know that it is safe to do this unlocked because a serialised
child will never become unserialised.

Closes #626320
This commit is contained in:
Ryan Lortie 2010-10-26 11:49:32 -04:00
parent e0caf4fd5e
commit 181982c47c

View File

@ -847,11 +847,23 @@ GVariant *
g_variant_get_child_value (GVariant *value, g_variant_get_child_value (GVariant *value,
gsize index_) gsize index_)
{ {
GVariant *child = NULL; if (~g_atomic_int_get (&value->state) & STATE_SERIALISED)
{
g_variant_lock (value); g_variant_lock (value);
if (value->state & STATE_SERIALISED) if (~value->state & STATE_SERIALISED)
{
GVariant *child;
child = g_variant_ref (value->contents.tree.children[index_]);
g_variant_unlock (value);
return child;
}
g_variant_unlock (value);
}
{ {
GVariantSerialised serialised = { GVariantSerialised serialised = {
value->type_info, value->type_info,
@ -859,6 +871,7 @@ g_variant_get_child_value (GVariant *value,
value->size value->size
}; };
GVariantSerialised s_child; GVariantSerialised s_child;
GVariant *child;
/* get the serialiser to extract the serialised data for the child /* get the serialiser to extract the serialised data for the child
* from the serialised data for the container * from the serialised data for the container
@ -875,14 +888,10 @@ g_variant_get_child_value (GVariant *value,
child->contents.serialised.buffer = child->contents.serialised.buffer =
g_buffer_ref (value->contents.serialised.buffer); g_buffer_ref (value->contents.serialised.buffer);
child->contents.serialised.data = s_child.data; child->contents.serialised.data = s_child.data;
}
else
child = g_variant_ref (value->contents.tree.children[index_]);
g_variant_unlock (value);
return child; return child;
} }
}
/** /**
* g_variant_store: * g_variant_store: