From bb0cc542b8f1bc00e210c5fecb53f1315fc0b81b Mon Sep 17 00:00:00 2001 From: Jakub Sitnicki Date: Wed, 13 Aug 2014 07:19:11 +0200 Subject: [PATCH] mu: Prune empty containers from the root set after splicing their children When the root set contains only one empty container with one child first promote the child container to the root set and only then remove the empty parent container so that the root set never goes empty. Also make mu_container_splice_children() do only one thing, that is promote one container's children to be another container's siblings. The resultant childless container is no longer removed by this function. Fixes #460. --- lib/mu-container.c | 2 -- lib/mu-container.h | 6 ++---- lib/mu-threader.c | 6 ++++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/mu-container.c b/lib/mu-container.c index fbe612ff..f0743ac5 100644 --- a/lib/mu-container.c +++ b/lib/mu-container.c @@ -275,8 +275,6 @@ mu_container_splice_children (MuContainer *c, MuContainer *sibling) children = sibling->child; sibling->child = NULL; - c = mu_container_remove_sibling (c, sibling); - return mu_container_append_siblings (c, children); } diff --git a/lib/mu-container.h b/lib/mu-container.h index 9f2686a8..6cd76889 100644 --- a/lib/mu-container.h +++ b/lib/mu-container.h @@ -128,14 +128,12 @@ MuContainer* mu_container_remove_child (MuContainer *c, MuContainer *child); MuContainer* mu_container_remove_sibling (MuContainer *c, MuContainer *sibling); /** - * promote sibling's children to be this container's siblings and - * remove the sibling + * promote sibling's children to be this container's siblings * * @param c a container instance * @param sibling a sibling of this container * - * @return the container with the sibling's children promoted and the - * sibling itself removed + * @return the container with the sibling's children promoted */ MuContainer* mu_container_splice_children (MuContainer *c, diff --git a/lib/mu-threader.c b/lib/mu-threader.c index c42e166c..1bb4c0f5 100644 --- a/lib/mu-threader.c +++ b/lib/mu-threader.c @@ -433,10 +433,12 @@ prune_empty_containers (MuContainer *root_set) /* and prune the root_set itself... */ for (cur = root_set; cur; cur = cur->next) { - if (cur->flags & MU_CONTAINER_FLAG_DELETE) + if (cur->flags & MU_CONTAINER_FLAG_DELETE) { root_set = mu_container_remove_sibling (root_set, cur); - else if (cur->flags & MU_CONTAINER_FLAG_SPLICE) + } else if (cur->flags & MU_CONTAINER_FLAG_SPLICE) { root_set = mu_container_splice_children (root_set, cur); + root_set = mu_container_remove_sibling (root_set, cur); + } } return root_set;