Chromium Code Reviews| Index: src/zone.h |
| diff --git a/src/zone.h b/src/zone.h |
| index 864846553a234d82cfd88c3e527f1f5c7416e654..db169d62c01dad0a9f2a4d7960bce1892a823dcf 100644 |
| --- a/src/zone.h |
| +++ b/src/zone.h |
| @@ -143,6 +143,19 @@ class Zone { |
| }; |
| +// The ZoneAllocationPolicy is used to specialize the generic data |
| +// structures to allocate themselves and their elements in the Zone. |
| +struct ZoneAllocationPolicy { |
| + public: |
| + ZoneAllocationPolicy(Zone* zone = NULL) : zone_(zone) { } |
| + INLINE(void* New(size_t size)); |
| + INLINE(static void Delete(void *pointer)) { } |
| + |
| + private: |
| + Zone* zone_; |
|
danno
2012/06/01 11:29:24
Put this back where it was later in the file. to m
|
| +}; |
| + |
| + |
| // ZoneObject is an abstraction that helps define classes of objects |
| // allocated in the Zone. Use it as a base class; see ast.h. |
| class ZoneObject { |
| @@ -164,38 +177,55 @@ class ZoneObject { |
| }; |
| -// The ZoneListAllocationPolicy is used to specialize the GenericList |
| -// implementation to allocate ZoneLists and their elements in the |
| -// Zone. |
| -class ZoneListAllocationPolicy { |
| - public: |
| - // Allocate 'size' bytes of memory in the zone. |
| - static void* New(int size); |
| - |
| - // De-allocation attempts are silently ignored. |
| - static void Delete(void* p) { } |
| -}; |
| - |
| - |
| // ZoneLists are growable lists with constant-time access to the |
| // elements. The list itself and all its elements are allocated in the |
| // Zone. ZoneLists cannot be deleted individually; you can delete all |
| // objects in the Zone by calling Zone::DeleteAll(). |
| template<typename T> |
| -class ZoneList: public List<T, ZoneListAllocationPolicy> { |
| +class ZoneList: public List<T, ZoneAllocationPolicy> { |
| public: |
| - INLINE(void* operator new(size_t size)); |
| - INLINE(void* operator new(size_t size, Zone* zone)); |
| - |
| // Construct a new ZoneList with the given capacity; the length is |
| // always zero. The capacity must be non-negative. |
| - explicit ZoneList(int capacity) |
| - : List<T, ZoneListAllocationPolicy>(capacity) { } |
| + explicit ZoneList(int capacity, Zone* zone = NULL) |
| + : List<T, ZoneAllocationPolicy>(capacity, ZoneAllocationPolicy(zone)) { } |
| + |
| + INLINE(void* operator new(size_t size, Zone* zone)); |
| + INLINE(void* operator new(size_t size)); |
| // Construct a new ZoneList by copying the elements of the given ZoneList. |
| - explicit ZoneList(const ZoneList<T>& other) |
| - : List<T, ZoneListAllocationPolicy>(other.length()) { |
| - AddAll(other); |
| + explicit ZoneList(const ZoneList<T>& other, Zone* zone = NULL) |
| + : List<T, ZoneAllocationPolicy>(other.length(), |
| + ZoneAllocationPolicy(zone)) { |
| + AddAll(other, ZoneAllocationPolicy(zone)); |
| + } |
| + |
| + // We override almost all List's public functions here so that the |
|
danno
2012/06/01 11:29:24
It's not really overriding. You're adding convenie
|
| + // user's can pass a Zone instead of the (more inconvenient) |
| + // ZoneAllocationPolicy. |
| + INLINE(void Add(const T& element, Zone* zone = NULL)) { |
| + List<T, ZoneAllocationPolicy>::Add(element, ZoneAllocationPolicy(zone)); |
| + } |
| + INLINE(void AddAll(const List<T, ZoneAllocationPolicy>& other, |
| + Zone* zone = NULL)) { |
| + List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone)); |
| + } |
| + INLINE(void AddAll(const Vector<T>& other, Zone* zone = NULL)) { |
| + List<T, ZoneAllocationPolicy>::AddAll(other, ZoneAllocationPolicy(zone)); |
| + } |
| + INLINE(void InsertAt(int index, const T& element, Zone* zone = NULL)) { |
| + List<T, ZoneAllocationPolicy>::InsertAt(index, element, |
| + ZoneAllocationPolicy(zone)); |
| + } |
| + INLINE(Vector<T> AddBlock(T value, int count, Zone* zone = NULL)) { |
| + return List<T, ZoneAllocationPolicy>::AddBlock(value, count, |
| + ZoneAllocationPolicy(zone)); |
| + } |
| + INLINE(void Allocate(int length, Zone* zone = NULL)) { |
| + List<T, ZoneAllocationPolicy>::Allocate(length, ZoneAllocationPolicy(zone)); |
| + } |
| + INLINE(void Initialize(int capacity, Zone* zone = NULL)) { |
| + List<T, ZoneAllocationPolicy>::Initialize(capacity, |
| + ZoneAllocationPolicy(zone)); |
| } |
| void operator delete(void* pointer) { UNREACHABLE(); } |
| @@ -232,15 +262,15 @@ class ZoneScope BASE_EMBEDDED { |
| // different configurations of a concrete splay tree (see splay-tree.h). |
| // The tree itself and all its elements are allocated in the Zone. |
| template <typename Config> |
| -class ZoneSplayTree: public SplayTree<Config, ZoneListAllocationPolicy> { |
| +class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> { |
| public: |
| ZoneSplayTree() |
| - : SplayTree<Config, ZoneListAllocationPolicy>() {} |
| + : SplayTree<Config, ZoneAllocationPolicy>() {} |
| ~ZoneSplayTree(); |
| }; |
| -typedef TemplateHashMapImpl<ZoneListAllocationPolicy> ZoneHashMap; |
| +typedef TemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; |
| } } // namespace v8::internal |