Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Unified Diff: src/zone-inl.h

Issue 211024: Eliminate recursion in ZoneSplayTree traversal. (Closed)
Patch Set: Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/zone.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+ }
}
« no previous file with comments | « src/zone.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698