diff --git a/src/zone-inl.h b/src/zone-inl.h index b3141a4810..121ba19b12 100644 --- a/src/zone-inl.h +++ b/src/zone-inl.h @@ -276,12 +276,19 @@ void ZoneSplayTree::Splay(const Key& key) { } -template -static void DoForEach(Node* node, Callback* callback) { - if (node == NULL) return; - DoForEach(node->left(), callback); - callback->Call(node->key(), node->value()); - DoForEach(node->right(), callback); +template template +void ZoneSplayTree::ForEach(Callback* callback) { + // Pre-allocate some space for tiny trees. + ZoneList 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()); + } } diff --git a/src/zone.h b/src/zone.h index cdbab32821..4e4f1d7224 100644 --- a/src/zone.h +++ b/src/zone.h @@ -204,10 +204,6 @@ class ZoneScope BASE_EMBEDDED { }; -template -static void DoForEach(Node* node, Callback* callback); - - // A zone splay tree. The config type parameter encapsulates the // different configurations of a concrete splay tree: // @@ -297,9 +293,7 @@ class ZoneSplayTree : public ZoneObject { }; template - void ForEach(Callback* c) { - DoForEach::Node, Callback>(root_, c); - } + void ForEach(Callback* callback); private: Node* root_;