| Index: src/list.h
|
| diff --git a/src/list.h b/src/list.h
|
| index ca2b7bce227b0035bbf82e478d31b977fc53a164..bae55a8bdac34c1095c858f351e7141e3663feda 100644
|
| --- a/src/list.h
|
| +++ b/src/list.h
|
| @@ -45,13 +45,19 @@ namespace internal {
|
| // the C free store or the zone; see zone.h.
|
|
|
| // Forward defined as
|
| -// template <typename T, class P = FreeStoreAllocationPolicy> class List;
|
| -template <typename T, class P>
|
| -class List {
|
| +// template <typename T, class Allocator = FreeStoreAllocator> class List;
|
| +//
|
| +// Implementation note: List privately inherits from Allocator to
|
| +// allow empty base class optimization.
|
| +template <typename T, class Allocator>
|
| +class List : private Allocator {
|
| public:
|
| -
|
| - List() { Initialize(0); }
|
| - INLINE(explicit List(int capacity)) { Initialize(capacity); }
|
| + explicit List(const Allocator& allocator = Allocator())
|
| + : Allocator(allocator) { Initialize(0); }
|
| + INLINE(explicit List(int capacity, const Allocator& allocator = Allocator()))
|
| + : Allocator(allocator) {
|
| + Initialize(capacity);
|
| + }
|
| INLINE(~List()) { DeleteData(data_); }
|
|
|
| // Deallocates memory used by the list and leaves the list in a consistent
|
| @@ -62,9 +68,11 @@ class List {
|
| }
|
|
|
| INLINE(void* operator new(size_t size)) {
|
| - return P::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 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
|
| @@ -91,7 +99,7 @@ class List {
|
| void Add(const T& element);
|
|
|
| // Add all the elements from the argument list to this list.
|
| - void AddAll(const List<T, P>& other);
|
| + void AddAll(const List<T, Allocator>& other);
|
|
|
| // Add all the elements from the vector to this list.
|
| void AddAll(const Vector<T>& other);
|
| @@ -147,8 +155,10 @@ class List {
|
| int capacity_;
|
| int length_;
|
|
|
| - 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)) {
|
| + return static_cast<T*>(this->Allocator::New(n * sizeof(T)));
|
| + }
|
| + INLINE(void DeleteData(T* data)) { this->Allocator::Delete(data); }
|
|
|
| // Increase the capacity of a full list, and add an element.
|
| // List must be full already.
|
|
|