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

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: Fixed the issues pointed out. 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
« no previous file with comments | « src/list-inl.h ('k') | src/splay-tree-inl.h » ('j') | src/splay-tree-inl.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/splay-tree.h
diff --git a/src/splay-tree.h b/src/splay-tree.h
index 72231e4d2a120a0fe3bf98eb12e52d3336ea6217..7c8163311c625111a4746934f823d4732377ca31 100644
--- a/src/splay-tree.h
+++ b/src/splay-tree.h
@@ -50,26 +50,34 @@ namespace internal {
// Forward defined as
// template <typename Config, class Allocator = FreeStoreAllocationPolicy>
// class SplayTree;
-template <typename Config, class Allocator>
+template <typename Config, class AllocationPolicy>
class SplayTree {
public:
typedef typename Config::Key Key;
typedef typename Config::Value Value;
+ typedef typename AllocationPolicy::Allocator Allocator;
+ typedef typename AllocationPolicy::Deallocator 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* ptr, size_t size)) {
+ reinterpret_cast<SplayTree*>(ptr)->deallocator_.Delete(ptr);
}
- 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 +120,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/31 11:03:36 Hmmm. This still seems dangerous. It seems to intr
}
Key key() { return key_; }
@@ -183,17 +191,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_;
DISALLOW_COPY_AND_ASSIGN(SplayTree);
};
« no previous file with comments | « src/list-inl.h ('k') | src/splay-tree-inl.h » ('j') | src/splay-tree-inl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698