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

Unified Diff: src/list.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
« no previous file with comments | « src/isolate.cc ('k') | src/list-inl.h » ('j') | src/splay-tree.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/list.h
diff --git a/src/list.h b/src/list.h
index 7350c0d44ecc57fd4d4915f499c4656544b860a3..d30e47008935760372ab18d4ba05f1fd8cc8a90a 100644
--- a/src/list.h
+++ b/src/list.h
@@ -49,8 +49,18 @@ namespace internal {
template <typename T, class P>
class List {
public:
- List() { Initialize(0); }
- INLINE(explicit List(int capacity)) { Initialize(capacity); }
+ typedef typename P::Alloc Allocator;
danno 2012/05/25 11:03:37 AllocationPolicy instead of P
+ typedef typename P::Dealloc Deallocator;
+ explicit List(Allocator allocator = Allocator(),
+ Deallocator deallocator = Deallocator())
+ : deallocator_(deallocator) {
+ Initialize(0, allocator);
+ }
+ INLINE(explicit List(int capacity, Allocator allocator = Allocator(),
+ Deallocator deallocator = Deallocator()))
+ : deallocator_(deallocator) {
+ Initialize(capacity, allocator);
+ }
INLINE(~List()) { DeleteData(data_); }
// Deallocates memory used by the list and leaves the list in a consistent
@@ -60,10 +70,12 @@ class List {
Initialize(0);
}
- INLINE(void* operator new(size_t size)) {
- return P::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)) {
+ reinterpret_cast<List*>(p)->deallocator_.Delete(p);
}
- INLINE(void operator delete(void* p, size_t)) { return P::Delete(p); }
// Returns a reference to the element at index i. This reference is
// not safe to use after operations that can change the list's
@@ -87,21 +99,21 @@ class List {
// Adds a copy of the given 'element' to the end of the list,
// expanding the list if necessary.
- void Add(const T& element);
+ void Add(const T& element, Allocator allocator = Allocator());
// Add all the elements from the argument list to this list.
- void AddAll(const List<T, P>& other);
+ void AddAll(const List<T, P>& other, Allocator allocator = Allocator());
// Add all the elements from the vector to this list.
- void AddAll(const Vector<T>& other);
+ void AddAll(const Vector<T>& other, Allocator allocator = Allocator());
// Inserts the element at the specific index.
- void InsertAt(int index, const T& element);
+ void InsertAt(int index, const T& element, Allocator allocator = Allocator());
// Added 'count' elements with the value 'value' and returns a
// vector that allows access to the elements. The vector is valid
// until the next change is made to this list.
- Vector<T> AddBlock(T value, int count);
+ Vector<T> AddBlock(T value, int count, Allocator allocator = Allocator());
// Removes the i'th element without deleting it even if T is a
// pointer type; moves all elements above i "down". Returns the
@@ -118,7 +130,7 @@ class List {
INLINE(T RemoveLast()) { return Remove(length_ - 1); }
// Deletes current list contents and allocates space for 'length' elements.
- INLINE(void Allocate(int length));
+ INLINE(void Allocate(int length, Allocator allocator = Allocator()));
// Clears the list by setting the length to zero. Even if T is a
// pointer type, clearing the list doesn't delete the entries.
@@ -142,26 +154,31 @@ class List {
void Sort(int (*cmp)(const T* x, const T* y));
void Sort();
- INLINE(void Initialize(int capacity));
+ INLINE(void Initialize(int capacity, Allocator allocator = Allocator()));
private:
T* data_;
int capacity_;
int length_;
+ Deallocator deallocator_;
- INLINE(T* NewData(int n)) { return static_cast<T*>(P::New(n * sizeof(T))); }
- INLINE(void DeleteData(T* data)) { P::Delete(data); }
+ INLINE(T* NewData(int n, Allocator allocator)) {
+ return static_cast<T*>(allocator.New(n * sizeof(T)));
+ }
+ INLINE(void DeleteData(T* data)) {
+ deallocator_.Delete(data);
+ }
// Increase the capacity of a full list, and add an element.
// List must be full already.
- void ResizeAdd(const T& element);
+ void ResizeAdd(const T& element, Allocator alloc);
// Inlined implementation of ResizeAdd, shared by inlined and
// non-inlined versions of ResizeAdd.
- void ResizeAddInternal(const T& element);
+ void ResizeAddInternal(const T& element, Allocator alloc);
// Resize the list.
- void Resize(int new_capacity);
+ void Resize(int new_capacity, Allocator alloc);
DISALLOW_COPY_AND_ASSIGN(List);
};
« no previous file with comments | « src/isolate.cc ('k') | src/list-inl.h » ('j') | src/splay-tree.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698