Skip to content

Commit

Permalink
Optimize tree walk
Browse files Browse the repository at this point in the history
Signed-off-by: ruben.vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed Feb 15, 2019
1 parent 5d0e712 commit 2c83dd5
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 });
while (nodeStack.length) {
const { node, depth: nodeDepth } = nodeStack.pop();
fn(node.value, node, nodeDepth);
actualDepth = nodeDepth + 1;
let i = node.children.length - 1;
while (i >= 0) {
nodeStack.push({ node: node.children[i], depth: actualDepth });
i--;
}
}
}
}

0 comments on commit 2c83dd5

Please sign in to comment.