Chromium Code Reviews| Index: src/splay-tree-inl.h |
| diff --git a/src/splay-tree-inl.h b/src/splay-tree-inl.h |
| index bb6ded7098b78d8f384e084e3d4adb88d9d6c7a7..b1fedecfe5bdb48fb54c61f66b08329497e2ec6e 100644 |
| --- a/src/splay-tree-inl.h |
| +++ b/src/splay-tree-inl.h |
| @@ -36,8 +36,17 @@ namespace internal { |
| template<typename Config, class Allocator> |
| SplayTree<Config, Allocator>::~SplayTree() { |
| - NodeDeleter deleter; |
| - ForEachNode(&deleter); |
| + // Pre-allocate some space for tiny trees. Since we don't have an |
| + // Allocator object here, we allocate the list on the heap. |
| + List<Node*> nodes_to_visit(10); |
| + if (root_ != NULL) nodes_to_visit.Add(root_); |
| + int pos = 0; |
| + while (pos < nodes_to_visit.length()) { |
| + Node* node = nodes_to_visit[pos++]; |
| + if (node->left() != NULL) nodes_to_visit.Add(node->left()); |
| + if (node->right() != NULL) nodes_to_visit.Add(node->right()); |
| + Allocator::Delete(node); |
| + } |
|
danno
2012/06/06 10:59:53
Store the allocator inside the splay tree so that
sanjoy
2012/06/06 11:43:54
Done.
|
| } |
| @@ -286,9 +295,10 @@ void SplayTree<Config, Allocator>::Splay(const Key& key) { |
| template <typename Config, class Allocator> template <class Callback> |
| -void SplayTree<Config, Allocator>::ForEach(Callback* callback) { |
| +void SplayTree<Config, Allocator>::ForEach(Callback* callback, |
| + Allocator allocator) { |
| NodeToPairAdaptor<Callback> callback_adaptor(callback); |
| - ForEachNode(&callback_adaptor); |
| + ForEachNode(&callback_adaptor, allocator); |
| } |
| @@ -296,7 +306,7 @@ template <typename Config, class Allocator> template <class Callback> |
| void SplayTree<Config, Allocator>::ForEachNode(Callback* callback, |
| Allocator allocator) { |
| // Pre-allocate some space for tiny trees. |
| - List<Node*, Allocator> nodes_to_visit(10); |
| + List<Node*, Allocator> nodes_to_visit(10, allocator); |
| if (root_ != NULL) nodes_to_visit.Add(root_, allocator); |
| int pos = 0; |
| while (pos < nodes_to_visit.length()) { |