gvariant-core: Consolidate construction of GVariantSerialised

So I only need to change it in one place.

This introduces no functional changes.

Helps: #2121
This commit is contained in:
William Manley 2020-06-23 22:59:58 +01:00 committed by Philip Withnall
parent 782b5cbee5
commit 1deacdd4e8

View File

@ -351,6 +351,27 @@ g_variant_ensure_size (GVariant *value)
}
}
/* < private >
* g_variant_to_serialised:
* @value: a #GVariant
*
* Gets a GVariantSerialised for a GVariant in state STATE_SERIALISED.
*/
inline static GVariantSerialised
g_variant_to_serialised (GVariant *value)
{
g_assert (value->state & STATE_SERIALISED);
{
GVariantSerialised serialised = {
value->type_info,
(gpointer) value->contents.serialised.data,
value->size,
value->depth,
};
return serialised;
}
}
/* < private >
* g_variant_serialise:
* @value: a #GVariant
@ -1009,16 +1030,8 @@ g_variant_n_children (GVariant *value)
g_variant_lock (value);
if (value->state & STATE_SERIALISED)
{
GVariantSerialised serialised = {
value->type_info,
(gpointer) value->contents.serialised.data,
value->size,
value->depth,
};
n_children = g_variant_serialised_n_children (serialised);
}
n_children = g_variant_serialised_n_children (
g_variant_to_serialised (value));
else
n_children = value->contents.tree.n_children;
@ -1085,12 +1098,7 @@ g_variant_get_child_value (GVariant *value,
}
{
GVariantSerialised serialised = {
value->type_info,
(gpointer) value->contents.serialised.data,
value->size,
value->depth,
};
GVariantSerialised serialised = g_variant_to_serialised (value);
GVariantSerialised s_child;
GVariant *child;
@ -1203,14 +1211,7 @@ g_variant_is_normal_form (GVariant *value)
if (value->state & STATE_SERIALISED)
{
GVariantSerialised serialised = {
value->type_info,
(gpointer) value->contents.serialised.data,
value->size,
value->depth
};
if (g_variant_serialised_is_normal (serialised))
if (g_variant_serialised_is_normal (g_variant_to_serialised (value)))
value->state |= STATE_TRUSTED;
}
else