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:
@ -275,8 +275,6 @@ mu_container_splice_children (MuContainer *c, MuContainer *sibling)
|
|||||||
children = sibling->child;
|
children = sibling->child;
|
||||||
sibling->child = NULL;
|
sibling->child = NULL;
|
||||||
|
|
||||||
c = mu_container_remove_sibling (c, sibling);
|
|
||||||
|
|
||||||
return mu_container_append_siblings (c, children);
|
return mu_container_append_siblings (c, children);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -128,14 +128,12 @@ MuContainer* mu_container_remove_child (MuContainer *c, MuContainer *child);
|
|||||||
MuContainer* mu_container_remove_sibling (MuContainer *c, MuContainer *sibling);
|
MuContainer* mu_container_remove_sibling (MuContainer *c, MuContainer *sibling);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* promote sibling's children to be this container's siblings and
|
* promote sibling's children to be this container's siblings
|
||||||
* remove the sibling
|
|
||||||
*
|
*
|
||||||
* @param c a container instance
|
* @param c a container instance
|
||||||
* @param sibling a sibling of this container
|
* @param sibling a sibling of this container
|
||||||
*
|
*
|
||||||
* @return the container with the sibling's children promoted and the
|
* @return the container with the sibling's children promoted
|
||||||
* sibling itself removed
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MuContainer* mu_container_splice_children (MuContainer *c,
|
MuContainer* mu_container_splice_children (MuContainer *c,
|
||||||
|
|||||||
@ -433,10 +433,12 @@ prune_empty_containers (MuContainer *root_set)
|
|||||||
|
|
||||||
/* and prune the root_set itself... */
|
/* and prune the root_set itself... */
|
||||||
for (cur = root_set; cur; cur = cur->next) {
|
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);
|
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_splice_children (root_set, cur);
|
||||||
|
root_set = mu_container_remove_sibling (root_set, cur);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return root_set;
|
return root_set;
|
||||||
|
|||||||
Reference in New Issue
Block a user