GVariant: calculate size at construction
authorRyan Lortie <desrt@desrt.ca>
Thu, 27 Nov 2014 21:37:13 +0000 (16:37 -0500)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Fri, 10 Jul 2015 09:47:42 +0000 (11:47 +0200)
commit03282541a8f86bc3b047773751ca9e0450974996
tree98dcf705a649475723f580d9d7edb8b0b177a2fa
parent25b35c2031088fb40fd37ace2ac7e1556b3662ae
GVariant: calculate size at construction

It's always possible to determine the serialised size of a GVariant
instance, even in the case that it is not yet serialised.  This can be
done by calling g_variant_get_size() which will base its answer on the
size of each child (which must be recursively determined).

We must perform this process before we can allocate the buffer to
serialise a GVariant into (since we must know the size of the buffer).
This means that serialising a GVariant involves two steps that recurse
through the entire tree of values.  We must take locks twice.

Simplify this by always determining the size when the instance is first
created, from the sizes of its children (which now will always be known
as well).  We can do this without taking any locks because the
newly-created instance has never been exposed and because the size on
the children is now a constant that can be directly accessed without a
lock.

This is a reduction in complexity and will also be a performance
improvement in all cases where a GVariant is serialised.  It will be a
slight performance hit in the case that we construct tree-form instances
and never serialise them.
glib/gvariant-core.c