From 5a14db50891196a9d17a0df49bf0858551e5a0af Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 26 Oct 2009 16:02:06 +0000 Subject: [PATCH] layout: Do not create a LayoutMeta on remove When calling remove_child_meta() we check if there is a LayoutMeta already attached to the Actor, and if that LayoutMeta matches the (manager, container, actor) tuple. If the LayoutMeta does not match, though, we create a new LayoutMeta instance -- in order to remove it right afterwards. Instead of doing this, we can simply check for a matching LayoutMeta and if present, remove it. In case of an existing, non-matching LayoutMeta, we're left with a dangling instance, but it does not matter: the removal happens in the unparenting phase of a ClutterContainer, so either the Actor will be destroyed and thus the LayoutMeta will be disposed along with it; or it will be parented to another container, and thus the LayoutMeta will be replaced. --- clutter/clutter-layout-manager.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/clutter/clutter-layout-manager.c b/clutter/clutter-layout-manager.c index 899c10305..baf4a10f8 100644 --- a/clutter/clutter-layout-manager.c +++ b/clutter/clutter-layout-manager.c @@ -381,6 +381,27 @@ create_child_meta (ClutterLayoutManager *manager, return klass->create_child_meta (manager, container, actor); } +static gboolean +has_child_meta (ClutterLayoutManager *manager, + ClutterContainer *container, + ClutterActor *actor) +{ + ClutterLayoutMeta *layout_meta = NULL; + + layout_meta = g_object_get_qdata (G_OBJECT (actor), quark_layout_meta); + if (layout_meta != NULL) + { + ClutterChildMeta *child_meta = CLUTTER_CHILD_META (layout_meta); + + if (layout_meta->manager == manager && + child_meta->container == container && + child_meta->actor == actor) + return TRUE; + } + + return FALSE; +} + static inline ClutterLayoutMeta * get_child_meta (ClutterLayoutManager *manager, ClutterContainer *container, @@ -550,7 +571,7 @@ clutter_layout_manager_remove_child_meta (ClutterLayoutManager *manager, g_return_if_fail (CLUTTER_IS_CONTAINER (container)); g_return_if_fail (CLUTTER_IS_ACTOR (actor)); - if (get_child_meta (manager, container, actor)) + if (has_child_meta (manager, container, actor)) g_object_set_qdata (G_OBJECT (actor), quark_layout_meta, NULL); }