- commit
- e6f4579a676980047deeb5d67569a28a74261596
- parent
- 524601e7cf43af9465cae550128e618d58307d0e
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-01-12 18:02
refactor: avoid recursion in walk()
Diffstat
| M | lib/atree.js | 10 | ++++++---- |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/atree.js b/lib/atree.js
@@ -65,10 +65,12 @@ var getChildNodes = function(node) {
65 65 };
66 66
67 67 var walk = function(root, fn) {
68 -1 fn(root);
69 -1 getChildNodes(root).forEach(function(child) {
70 -1 walk(child, fn);
71 -1 });
-1 68 var queue = [root];
-1 69 while (queue.length) {
-1 70 var item = queue.shift();
-1 71 fn(item);
-1 72 queue = getChildNodes(item).concat(queue);
-1 73 }
72 74 };
73 75
74 76 var searchUp = function(node, test) {