gvariant: Port g_variant_deep_copy() to count its iterations directly

This is equivalent to what `GVariantIter` does, but it means that
`g_variant_deep_copy()` is making its own `g_variant_get_child_value()`
calls.

This will be useful in an upcoming commit, where those child values will
be inspected a little more deeply.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2121
This commit is contained in:
Philip Withnall 2022-10-24 18:43:55 +01:00
parent 35dee77ed8
commit e6490c84e8

View File

@ -5863,14 +5863,13 @@ g_variant_deep_copy (GVariant *value)
case G_VARIANT_CLASS_VARIANT: case G_VARIANT_CLASS_VARIANT:
{ {
GVariantBuilder builder; GVariantBuilder builder;
GVariantIter iter; gsize i, n_children;
GVariant *child;
g_variant_builder_init (&builder, g_variant_get_type (value)); g_variant_builder_init (&builder, g_variant_get_type (value));
g_variant_iter_init (&iter, value);
while ((child = g_variant_iter_next_value (&iter))) for (i = 0, n_children = g_variant_n_children (value); i < n_children; i++)
{ {
GVariant *child = g_variant_get_child_value (value, i);
g_variant_builder_add_value (&builder, g_variant_deep_copy (child)); g_variant_builder_add_value (&builder, g_variant_deep_copy (child));
g_variant_unref (child); g_variant_unref (child);
} }