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

Unified Diff: src/splay-tree.h

Issue 7374002: Refactor allocation policies. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 5 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/scopes.cc ('k') | src/splay-tree-inl.h » ('j') | no next file with comments »
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 0cb9ea8405dd0bb7265f6737ff06d24ee7729207..2fcbcb26e3214782253d613e43075b6a49a2ad95 100644
--- a/src/splay-tree.h
+++ b/src/splay-tree.h
@@ -48,7 +48,7 @@ namespace internal {
// store or the zone; see zone.h.
// Forward defined as
-// template <typename Config, class Allocator = FreeStoreAllocationPolicy>
+// template <typename Config, class Allocator = FreeStoreAllocator>
// class SplayTree;
template <typename Config, class Allocator>
class SplayTree {
@@ -58,13 +58,16 @@ class SplayTree {
class Locator;
- SplayTree() : root_(NULL) { }
+ explicit SplayTree(const Allocator& allocator = Allocator())
+ : allocator_(allocator), root_(NULL) { }
~SplayTree();
INLINE(void* operator new(size_t size)) {
- return Allocator::New(static_cast<int>(size));
+ return Allocator().New(static_cast<int>(size));
+ }
+ INLINE(void operator delete(void* p, size_t)) {
+ return Allocator().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
@@ -112,11 +115,12 @@ 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);
+ static void Delete(Allocator* allocator, Node* node) {
+ node->~Node();
+ allocator->Delete(node);
}
Key key() { return key_; }
@@ -124,6 +128,7 @@ class SplayTree {
Node* left() { return left_; }
Node* right() { return right_; }
private:
+ void operator delete(void* p, size_t);
friend class SplayTree;
friend class Locator;
@@ -183,10 +188,11 @@ class SplayTree {
class NodeDeleter BASE_EMBEDDED {
public:
- NodeDeleter() { }
- void Call(Node* node) { delete node; }
+ explicit NodeDeleter(Allocator* allocator) : allocator_(allocator) { }
+ void Call(Node* node) { Node::Delete(allocator_, node); }
private:
+ Allocator* allocator_;
DISALLOW_COPY_AND_ASSIGN(NodeDeleter);
};
@@ -194,6 +200,7 @@ class SplayTree {
template <class Callback>
void ForEachNode(Callback* callback);
+ Allocator allocator_;
Node* root_;
DISALLOW_COPY_AND_ASSIGN(SplayTree);
« no previous file with comments | « src/scopes.cc ('k') | src/splay-tree-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698