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

Unified Diff: src/splay-tree.h

Issue 10448007: Split an allocation policy into an allocator and a deallocator. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Make TemplateHashMapImpl consistent with the rest of the approach. Created 8 years, 7 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
Index: src/splay-tree.h
diff --git a/src/splay-tree.h b/src/splay-tree.h
index 72231e4d2a120a0fe3bf98eb12e52d3336ea6217..7ed20871fab11a98fa32928a2c97d89d558e0f82 100644
--- a/src/splay-tree.h
+++ b/src/splay-tree.h
@@ -50,26 +50,35 @@ namespace internal {
// Forward defined as
// template <typename Config, class Allocator = FreeStoreAllocationPolicy>
// class SplayTree;
-template <typename Config, class Allocator>
+template <typename Config, class P>
danno 2012/05/25 11:03:37 AllocationPolicy
class SplayTree {
public:
typedef typename Config::Key Key;
typedef typename Config::Value Value;
+ typedef typename P::Alloc Allocator;
+ typedef typename P::Dealloc Deallocator;
+
class Locator;
- SplayTree() : root_(NULL) { }
+ SplayTree(Allocator allocator = Allocator(),
+ Deallocator deallocator = Deallocator())
+ : root_(NULL), deallocator_(deallocator) { }
~SplayTree();
- INLINE(void* operator new(size_t size)) {
- return Allocator::New(static_cast<int>(size));
+ INLINE(void* operator new(size_t size, Allocator allocator = Allocator())) {
+ return allocator.New(static_cast<int>(size));
+ }
+ INLINE(void operator delete(void* p, size_t,
+ Deallocator deallocator = Deallocator())) {
danno 2012/05/25 11:03:37 Adding the deallocator here does something differe
+ return deallocator.Delete(p);
}
- INLINE(void operator delete(void* p, size_t)) { return Allocator::Delete(p); }
// Inserts the given key in this tree with the given value. Returns
// true if a node was inserted, otherwise false. If found the locator
// is enabled and provides access to the mapping for the key.
- bool Insert(const Key& key, Locator* locator);
+ bool Insert(const Key& key, Locator* locator,
+ Allocator allocator = Allocator());
// Looks up the key in this tree and returns true if it was found,
// otherwise false. If the node is found the locator is enabled and
@@ -112,11 +121,11 @@ class SplayTree {
left_(NULL),
right_(NULL) { }
- INLINE(void* operator new(size_t size)) {
- return Allocator::New(static_cast<int>(size));
+ INLINE(void* operator new(size_t size, Allocator allocator)) {
+ return allocator.New(static_cast<int>(size));
}
INLINE(void operator delete(void* p, size_t)) {
- return Allocator::Delete(p);
+ UNREACHABLE();
danno 2012/05/25 11:03:37 Why unreachable? Because nodes should only be allo
sanjoy1 2012/05/25 20:32:44 The nodes are deleted using Deallocator::Delete, w
}
Key key() { return key_; }
@@ -183,17 +192,21 @@ class SplayTree {
class NodeDeleter BASE_EMBEDDED {
public:
- NodeDeleter() { }
- void Call(Node* node) { delete node; }
+ explicit NodeDeleter(Deallocator deallocator) : deallocator_(deallocator) {
+ }
+ void Call(Node* node) { deallocator_.Delete(node); }
private:
+ Deallocator deallocator_;
+
DISALLOW_COPY_AND_ASSIGN(NodeDeleter);
};
template <class Callback>
- void ForEachNode(Callback* callback);
+ void ForEachNode(Callback* callback, Allocator allocator = Allocator());
Node* root_;
+ Deallocator deallocator_;
danno 2012/05/25 11:03:37 I don't think you ever need to store the Deallocat
sanjoy1 2012/05/25 20:32:44 I need to store it in case the we're using the Pre
DISALLOW_COPY_AND_ASSIGN(SplayTree);
};

Powered by Google App Engine
This is Rietveld 408576698