1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef V8_ZONE_CONTAINERS_H_
6 #define V8_ZONE_CONTAINERS_H_
12 #include "src/zone-allocator.h"
17 // A wrapper subclass for std::vector to make it easy to construct one
18 // that uses a zone allocator.
20 class ZoneVector : public std::vector<T, zone_allocator<T> > {
22 // Constructs an empty vector.
23 explicit ZoneVector(Zone* zone)
24 : std::vector<T, zone_allocator<T> >(zone_allocator<T>(zone)) {}
26 // Constructs a new vector and fills it with {size} elements, each
27 // constructed via the default constructor.
28 ZoneVector(int size, Zone* zone)
29 : std::vector<T, zone_allocator<T> >(size, T(), zone_allocator<T>(zone)) {
32 // Constructs a new vector and fills it with {size} elements, each
33 // having the value {def}.
34 ZoneVector(int size, T def, Zone* zone)
35 : std::vector<T, zone_allocator<T> >(size, def, zone_allocator<T>(zone)) {
39 // A wrapper subclass std::deque to make it easy to construct one
40 // that uses a zone allocator.
42 class ZoneDeque : public std::deque<T, zone_allocator<T> > {
44 explicit ZoneDeque(Zone* zone)
45 : std::deque<T, zone_allocator<T> >(zone_allocator<T>(zone)) {}
48 // A wrapper subclass for std::queue to make it easy to construct one
49 // that uses a zone allocator.
51 class ZoneQueue : public std::queue<T, std::deque<T, zone_allocator<T> > > {
53 // Constructs an empty queue.
54 explicit ZoneQueue(Zone* zone)
55 : std::queue<T, std::deque<T, zone_allocator<T> > >(
56 std::deque<T, zone_allocator<T> >(zone_allocator<T>(zone))) {}
59 // Typedefs to shorten commonly used vectors.
60 typedef ZoneVector<bool> BoolVector;
61 typedef ZoneVector<int> IntVector;
62 } } // namespace v8::internal
64 #endif // V8_ZONE_CONTAINERS_H_