From c2287696b15af7f1e737e66f38ba4b17282b40d4 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 24 Mar 2020 22:25:47 -0300 Subject: [PATCH] timeline:element: Refactor the way we 'copy' Simplifying the implementation and making sure assets are set asap --- ges/ges-timeline-element.c | 49 +++++++++------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/ges/ges-timeline-element.c b/ges/ges-timeline-element.c index 2a2a206..81c9529 100644 --- a/ges/ges-timeline-element.c +++ b/ges/ges-timeline-element.c @@ -1655,10 +1655,9 @@ GESTimelineElement * ges_timeline_element_copy (GESTimelineElement * self, gboolean deep) { GESAsset *asset; - GParameter *params; GParamSpec **specs; GESTimelineElementClass *klass; - guint n, n_specs, n_params; + guint n, n_specs; GESTimelineElement *ret = NULL; @@ -1667,56 +1666,26 @@ ges_timeline_element_copy (GESTimelineElement * self, gboolean deep) klass = GES_TIMELINE_ELEMENT_GET_CLASS (self); specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (self), &n_specs); - params = g_new0 (GParameter, n_specs); - n_params = 0; + asset = ges_extractable_get_asset (GES_EXTRACTABLE (self)); + g_assert (asset); + ret = GES_TIMELINE_ELEMENT (ges_asset_extract (asset, NULL)); for (n = 0; n < n_specs; ++n) { /* We do not want the timeline or the name to be copied */ if (g_strcmp0 (specs[n]->name, "parent") && g_strcmp0 (specs[n]->name, "timeline") && g_strcmp0 (specs[n]->name, "name") && (specs[n]->flags & G_PARAM_READWRITE) == G_PARAM_READWRITE) { - params[n_params].name = g_intern_string (specs[n]->name); - g_value_init (¶ms[n_params].value, specs[n]->value_type); - g_object_get_property (G_OBJECT (self), specs[n]->name, - ¶ms[n_params].value); - ++n_params; - } - } + GValue v = G_VALUE_INIT; + g_value_init (&v, specs[n]->value_type); + g_object_get_property (G_OBJECT (self), specs[n]->name, &v); -#if GLIB_CHECK_VERSION(2, 53, 1) - { - gint i; - GValue *values; - const gchar **names; - values = g_malloc0 (sizeof (GValue) * n_specs); - names = g_malloc0 (sizeof (gchar *) * n_specs); - - for (i = 0; i < n_params; i++) { - values[i] = params[i].value; - names[i] = params[i].name; + g_object_set_property (G_OBJECT (ret), specs[n]->name, &v); + g_value_reset (&v); } - - ret = - GES_TIMELINE_ELEMENT (g_object_new_with_properties (G_OBJECT_TYPE - (self), n_params, names, values)); - g_free (names); - g_free (values); } -#else - ret = g_object_newv (G_OBJECT_TYPE (self), n_params, params); -#endif - - while (n_params--) - g_value_unset (¶ms[n_params].value); g_free (specs); - g_free (params); - - - asset = ges_extractable_get_asset (GES_EXTRACTABLE (self)); - if (asset) - ges_extractable_set_asset (GES_EXTRACTABLE (ret), asset); if (deep) { if (klass->deep_copy) klass->deep_copy (self, ret); -- 2.7.4