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.
This commit is contained in:
Jakub Sitnicki 2014-08-13 07:19:11 +02:00
parent ede481d4c0
commit bb0cc542b8
3 changed files with 6 additions and 8 deletions

View File

@ -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);
}

View File

@ -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,

View File

@ -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;