Skip to content

Commit

Permalink
Optimize tree walk
Browse files Browse the repository at this point in the history
Signed-off-by: ruben.vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 committed Feb 11, 2019
1 parent f66f737 commit 3d691f8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/jaeger-ui/src/utils/TreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,18 @@ export default class TreeNode {
}

walk(fn, depth = 0) {
TreeNode.iterFunction(fn, depth)(this);
this.children.forEach(child => child.walk(fn, depth + 1));
const nodeStack = [];
let actualDepth = depth;
nodeStack.push({ node: this, depth: actualDepth });
const pushChildren = n => nodeStack.push({ node: n, depth: actualDepth });
while (nodeStack.length) {
const { node, nodeDepth } = nodeStack.pop();
TreeNode.iterFunction(fn, nodeDepth)(node);
actualDepth++;
node.children
.slice()
.reverse()
.forEach(pushChildren);
}
}
}

0 comments on commit 3d691f8

Please sign in to comment.