Index: src/zone-inl.h |
diff --git a/src/zone-inl.h b/src/zone-inl.h |
index b3141a4810d281e76c51e000a31584c9f0784444..121ba19b12e2cf08ece1e703540d2bc4c3453171 100644 |
--- a/src/zone-inl.h |
+++ b/src/zone-inl.h |
@@ -276,12 +276,19 @@ void ZoneSplayTree<C>::Splay(const Key& key) { |
} |
-template <typename Node, class Callback> |
-static void DoForEach(Node* node, Callback* callback) { |
- if (node == NULL) return; |
- DoForEach<Node, Callback>(node->left(), callback); |
- callback->Call(node->key(), node->value()); |
- DoForEach<Node, Callback>(node->right(), callback); |
+template <typename Config> template <class Callback> |
+void ZoneSplayTree<Config>::ForEach(Callback* callback) { |
+ // Pre-allocate some space for tiny trees. |
+ ZoneList<Node*> nodes_to_visit(10); |
+ nodes_to_visit.Add(root_); |
+ int pos = 0; |
+ while (pos < nodes_to_visit.length()) { |
+ Node* node = nodes_to_visit[pos++]; |
+ if (node == NULL) continue; |
+ callback->Call(node->key(), node->value()); |
+ nodes_to_visit.Add(node->left()); |
+ nodes_to_visit.Add(node->right()); |
+ } |
} |