From 1726304d72f766777c3e8f6a15f789fdaec5803e Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Mon, 3 Jun 2013 18:41:08 +0100 Subject: Simplify tree walker. --- desktop/treeview.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/desktop/treeview.c b/desktop/treeview.c index 9d3dce54a..02dd7e208 100644 --- a/desktop/treeview.c +++ b/desktop/treeview.c @@ -573,34 +573,24 @@ static bool treeview_walk_internal(struct treeview_node *root, bool full, node->children : NULL; if (next != NULL) { - /* down to children */ + /* Down to children */ node = next; inset += tree_g.step_width; } else { - /* no children */ - next = node->sibling_next; - - if (next != NULL && node != root) { - /* on to next sibling */ - node = next; - } else { - /* no next sibling */ - while (node != root) { - next = node->sibling_next; - - if (next != NULL) { - break; - } - - node = node->parent; - inset -= tree_g.step_width; - } + /* No children. As long as we're not at the root, + * go to next sibling if present, or nearest ancestor + * with a next sibling. */ + + while (node != root && + node->sibling_next == NULL) { + node = node->parent; + inset -= tree_g.step_width; + } - if (node == root) - break; + if (node == root) + break; - node = node->sibling_next; - } + node = node->sibling_next; } assert(node != NULL); -- cgit v1.2.3