mirror of https://github.com/djcb/mu.git
mu: Prune empty container when an only child gets promoted to the root set
This commit is contained in:
parent
f724f4a57d
commit
97101f1f82
|
@ -263,9 +263,24 @@ mu_container_foreach (MuContainer *c, MuContainerForeachFunc func,
|
|||
return func (c, user_data);
|
||||
}
|
||||
|
||||
MuContainer*
|
||||
mu_container_splice_children (MuContainer *c, MuContainer *sibling)
|
||||
{
|
||||
MuContainer *children;
|
||||
|
||||
g_return_val_if_fail (c, NULL);
|
||||
g_return_val_if_fail (sibling, NULL);
|
||||
|
||||
children = sibling->child;
|
||||
sibling->child = NULL;
|
||||
|
||||
c = mu_container_remove_sibling (c, sibling);
|
||||
|
||||
return mu_container_append_siblings (c, children);
|
||||
}
|
||||
|
||||
MuContainer*
|
||||
mu_container_splice_children (MuContainer *parent, MuContainer *child)
|
||||
mu_container_splice_grandchildren (MuContainer *parent, MuContainer *child)
|
||||
{
|
||||
MuContainer *newchild;
|
||||
|
||||
|
|
|
@ -122,6 +122,19 @@ 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
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
|
||||
MuContainer* mu_container_splice_children (MuContainer *c,
|
||||
MuContainer *sibling);
|
||||
|
||||
/**
|
||||
* promote child's children to be parent's children and remove child
|
||||
|
@ -131,8 +144,8 @@ MuContainer* mu_container_remove_sibling (MuContainer *c, MuContainer *sibling);
|
|||
*
|
||||
* @return the new container with it's children's children promoted
|
||||
*/
|
||||
MuContainer* mu_container_splice_children (MuContainer *parent,
|
||||
MuContainer *child);
|
||||
MuContainer* mu_container_splice_grandchildren (MuContainer *parent,
|
||||
MuContainer *child);
|
||||
|
||||
typedef gboolean (*MuContainerForeachFunc) (MuContainer*, gpointer);
|
||||
|
||||
|
|
|
@ -388,7 +388,7 @@ prune_maybe (MuContainer *c)
|
|||
if (cur->flags & MU_CONTAINER_FLAG_DELETE)
|
||||
c = mu_container_remove_child (c, cur);
|
||||
else if (cur->flags & MU_CONTAINER_FLAG_SPLICE)
|
||||
c = mu_container_splice_children (c, cur);
|
||||
c = mu_container_splice_grandchildren (c, cur);
|
||||
}
|
||||
|
||||
g_return_val_if_fail (c, FALSE);
|
||||
|
@ -433,17 +433,10 @@ 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)
|
||||
root_set = mu_container_remove_sibling (root_set, cur);
|
||||
|
||||
else if (cur->flags & MU_CONTAINER_FLAG_SPLICE) {
|
||||
MuContainer *newchild;
|
||||
newchild = cur->child;
|
||||
cur->child = NULL;
|
||||
root_set = mu_container_append_siblings (root_set,
|
||||
newchild);
|
||||
}
|
||||
else if (cur->flags & MU_CONTAINER_FLAG_SPLICE)
|
||||
root_set = mu_container_splice_children (root_set, cur);
|
||||
}
|
||||
|
||||
return root_set;
|
||||
|
|
Loading…
Reference in New Issue