Commit 9c263a6c authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

pstree: Simplify pstree_item_next

It's a deep first search used here so the code can be shrinked.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 59e80d4f
......@@ -47,28 +47,19 @@ struct pstree_item *__alloc_pstree_item(bool rst)
return item;
}
/* Deep first search on children */
struct pstree_item *pstree_item_next(struct pstree_item *item)
{
if (!list_empty(&item->children)) {
item = list_first_entry(&item->children, struct pstree_item, list);
return item;
}
if (!list_empty(&item->children))
return list_first_entry(&item->children, struct pstree_item, list);
while (1) {
if (item->parent == NULL) {
item = NULL;
break;
}
if (item->list.next == &item->parent->children) {
item = item->parent;
continue;
} else {
item = list_entry(item->list.next, struct pstree_item, list);
break;
}
while (item->parent) {
if (item->list.next != &item->parent->children)
return list_entry(item->list.next, struct pstree_item, list);
item = item->parent;
}
return item;
return NULL;
}
int dump_pstree(struct pstree_item *root_item)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment