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) ...@@ -47,28 +47,19 @@ struct pstree_item *__alloc_pstree_item(bool rst)
return item; return item;
} }
/* Deep first search on children */
struct pstree_item *pstree_item_next(struct pstree_item *item) struct pstree_item *pstree_item_next(struct pstree_item *item)
{ {
if (!list_empty(&item->children)) { if (!list_empty(&item->children))
item = list_first_entry(&item->children, struct pstree_item, list); return list_first_entry(&item->children, struct pstree_item, list);
return item;
}
while (1) { while (item->parent) {
if (item->parent == NULL) { if (item->list.next != &item->parent->children)
item = NULL; return list_entry(item->list.next, struct pstree_item, list);
break;
}
if (item->list.next == &item->parent->children) {
item = item->parent; item = item->parent;
continue;
} else {
item = list_entry(item->list.next, struct pstree_item, list);
break;
}
} }
return item; return NULL;
} }
int dump_pstree(struct pstree_item *root_item) 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