glib/gbytes: save small byte buffers inline
When dealing with small allocations it can save considerable cycles to
do a single allocation for both the GBytes
and the data by tacking it
onto the end of the GBytes
.
Care is taken to preserve the glibc expectation of 2*sizeof(void*)
alignment of allocations at the expense of some padding bytes.
The degenerate case here is when you want to steal the bytes afterwards but that amounts to the same overhead as the status-quo.
Where this can help considerably is in GVariant
building such as
g_variant_new_int32()
which allocates for the GVariant
, the GBytes
, and
the int32
within the GBytes
.
In a simple benchmark of using GVariantBuilder
to create (ii)
variants
this saved about 10% in wallclock time.
Edited by Christian Hergert