diff options
Diffstat (limited to 'src/3rdparty/v8/src/list.h')
-rw-r--r-- | src/3rdparty/v8/src/list.h | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/src/3rdparty/v8/src/list.h b/src/3rdparty/v8/src/list.h index 7350c0d..7fd4f5c 100644 --- a/src/3rdparty/v8/src/list.h +++ b/src/3rdparty/v8/src/list.h @@ -45,12 +45,18 @@ 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> +// template <typename T, +// class AllocationPolicy = FreeStoreAllocationPolicy> class List; +template <typename T, class AllocationPolicy> class List { public: - List() { Initialize(0); } - INLINE(explicit List(int capacity)) { Initialize(capacity); } + explicit List(AllocationPolicy allocator = AllocationPolicy()) { + Initialize(0, allocator); + } + INLINE(explicit List(int capacity, + AllocationPolicy allocator = AllocationPolicy())) { + Initialize(capacity, allocator); + } INLINE(~List()) { DeleteData(data_); } // Deallocates memory used by the list and leaves the list in a consistent @@ -60,10 +66,18 @@ 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, + AllocationPolicy allocator = AllocationPolicy())) { + return allocator.New(static_cast<int>(size)); + } + INLINE(void operator delete(void* p)) { + AllocationPolicy::Delete(p); + } + + // Please the MSVC compiler. We should never have to execute this. + INLINE(void operator delete(void* p, AllocationPolicy allocator)) { + UNREACHABLE(); } - 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 +101,25 @@ 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, AllocationPolicy allocator = AllocationPolicy()); // Add all the elements from the argument list to this list. - void AddAll(const List<T, P>& other); + void AddAll(const List<T, AllocationPolicy>& other, + AllocationPolicy allocator = AllocationPolicy()); // Add all the elements from the vector to this list. - void AddAll(const Vector<T>& other); + void AddAll(const Vector<T>& other, + AllocationPolicy allocator = AllocationPolicy()); // Inserts the element at the specific index. - void InsertAt(int index, const T& element); + void InsertAt(int index, const T& element, + AllocationPolicy allocator = AllocationPolicy()); // 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, + AllocationPolicy allocator = AllocationPolicy()); // 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 +136,8 @@ 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, + AllocationPolicy allocator = AllocationPolicy())); // 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 +161,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, + AllocationPolicy allocator = AllocationPolicy())); private: T* data_; 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, AllocationPolicy allocator)) { + return static_cast<T*>(allocator.New(n * sizeof(T))); + } + INLINE(void DeleteData(T* data)) { + AllocationPolicy::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, AllocationPolicy allocator); // Inlined implementation of ResizeAdd, shared by inlined and // non-inlined versions of ResizeAdd. - void ResizeAddInternal(const T& element); + void ResizeAddInternal(const T& element, AllocationPolicy allocator); // Resize the list. - void Resize(int new_capacity); + void Resize(int new_capacity, AllocationPolicy allocator); DISALLOW_COPY_AND_ASSIGN(List); }; |