// Copyright 2014 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_SRC_ZONE_ZONE_CONTAINERS_H_ #define V8_SRC_ZONE_ZONE_CONTAINERS_H_ #include #include #include #include #include #include #include #include "src/zone/zone-allocator.h" namespace v8 { namespace internal { // A wrapper subclass for std::vector to make it easy to construct one // that uses a zone allocator. template class ZoneVector : public std::vector> { public: // Constructs an empty vector. explicit ZoneVector(Zone* zone) : std::vector>(zone_allocator(zone)) {} // Constructs a new vector and fills it with {size} elements, each // constructed via the default constructor. ZoneVector(size_t size, Zone* zone) : std::vector>(size, T(), zone_allocator(zone)) {} // Constructs a new vector and fills it with {size} elements, each // having the value {def}. ZoneVector(size_t size, T def, Zone* zone) : std::vector>(size, def, zone_allocator(zone)) {} // Constructs a new vector and fills it with the contents of the range // [first, last). template ZoneVector(InputIt first, InputIt last, Zone* zone) : std::vector>(first, last, zone_allocator(zone)) {} }; // A wrapper subclass std::deque to make it easy to construct one // that uses a zone allocator. template class ZoneDeque : public std::deque> { public: // Constructs an empty deque. explicit ZoneDeque(Zone* zone) : std::deque>(zone_allocator(zone)) {} }; // A wrapper subclass std::list to make it easy to construct one // that uses a zone allocator. // TODO(mstarzinger): This should be renamed to ZoneList once we got rid of our // own home-grown ZoneList that actually is a ZoneVector. template class ZoneLinkedList : public std::list> { public: // Constructs an empty list. explicit ZoneLinkedList(Zone* zone) : std::list>(zone_allocator(zone)) {} }; // A wrapper subclass std::priority_queue to make it easy to construct one // that uses a zone allocator. template > class ZonePriorityQueue : public std::priority_queue, Compare> { public: // Constructs an empty list. explicit ZonePriorityQueue(Zone* zone) : std::priority_queue, Compare>(Compare(), ZoneVector(zone)) {} }; // A wrapper subclass for std::queue to make it easy to construct one // that uses a zone allocator. template class ZoneQueue : public std::queue> { public: // Constructs an empty queue. explicit ZoneQueue(Zone* zone) : std::queue>(ZoneDeque(zone)) {} }; // A wrapper subclass for std::stack to make it easy to construct one that uses // a zone allocator. template class ZoneStack : public std::stack> { public: // Constructs an empty stack. explicit ZoneStack(Zone* zone) : std::stack>(ZoneDeque(zone)) {} }; // A wrapper subclass for std::set to make it easy to construct one that uses // a zone allocator. template > class ZoneSet : public std::set> { public: // Constructs an empty set. explicit ZoneSet(Zone* zone) : std::set>(Compare(), zone_allocator(zone)) {} }; // A wrapper subclass for std::map to make it easy to construct one that uses // a zone allocator. template > class ZoneMap : public std::map>> { public: // Constructs an empty map. explicit ZoneMap(Zone* zone) : std::map>>( Compare(), zone_allocator>(zone)) {} }; // A wrapper subclass for std::multimap to make it easy to construct one that // uses a zone allocator. template > class ZoneMultimap : public std::multimap>> { public: // Constructs an empty multimap. explicit ZoneMultimap(Zone* zone) : std::multimap>>( Compare(), zone_allocator>(zone)) {} }; // Typedefs to shorten commonly used vectors. typedef ZoneVector BoolVector; typedef ZoneVector IntVector; } // namespace internal } // namespace v8 #endif // V8_SRC_ZONE_ZONE_CONTAINERS_H_