OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_ZONE_CONTAINERS_H_ | 5 #ifndef V8_ZONE_CONTAINERS_H_ |
6 #define V8_ZONE_CONTAINERS_H_ | 6 #define V8_ZONE_CONTAINERS_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
| 9 #include <list> |
9 #include <queue> | 10 #include <queue> |
10 #include <stack> | 11 #include <stack> |
11 #include <vector> | 12 #include <vector> |
12 | 13 |
13 #include "src/zone-allocator.h" | 14 #include "src/zone-allocator.h" |
14 | 15 |
15 namespace v8 { | 16 namespace v8 { |
16 namespace internal { | 17 namespace internal { |
17 | 18 |
18 // A wrapper subclass for std::vector to make it easy to construct one | 19 // A wrapper subclass for std::vector to make it easy to construct one |
19 // that uses a zone allocator. | 20 // that uses a zone allocator. |
20 template <typename T> | 21 template <typename T> |
21 class ZoneVector : public std::vector<T, zone_allocator<T> > { | 22 class ZoneVector : public std::vector<T, zone_allocator<T>> { |
22 public: | 23 public: |
23 // Constructs an empty vector. | 24 // Constructs an empty vector. |
24 explicit ZoneVector(Zone* zone) | 25 explicit ZoneVector(Zone* zone) |
25 : std::vector<T, zone_allocator<T> >(zone_allocator<T>(zone)) {} | 26 : std::vector<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} |
26 | 27 |
27 // Constructs a new vector and fills it with {size} elements, each | 28 // Constructs a new vector and fills it with {size} elements, each |
28 // constructed via the default constructor. | 29 // constructed via the default constructor. |
29 ZoneVector(int size, Zone* zone) | 30 ZoneVector(int size, Zone* zone) |
30 : std::vector<T, zone_allocator<T> >(size, T(), zone_allocator<T>(zone)) { | 31 : std::vector<T, zone_allocator<T>>(size, T(), zone_allocator<T>(zone)) {} |
31 } | |
32 | 32 |
33 // Constructs a new vector and fills it with {size} elements, each | 33 // Constructs a new vector and fills it with {size} elements, each |
34 // having the value {def}. | 34 // having the value {def}. |
35 ZoneVector(int size, T def, Zone* zone) | 35 ZoneVector(int size, T def, Zone* zone) |
36 : std::vector<T, zone_allocator<T> >(size, def, zone_allocator<T>(zone)) { | 36 : std::vector<T, zone_allocator<T>>(size, def, zone_allocator<T>(zone)) {} |
37 } | |
38 }; | 37 }; |
39 | 38 |
40 | 39 |
41 // A wrapper subclass std::deque to make it easy to construct one | 40 // A wrapper subclass std::deque to make it easy to construct one |
42 // that uses a zone allocator. | 41 // that uses a zone allocator. |
43 template <typename T> | 42 template <typename T> |
44 class ZoneDeque : public std::deque<T, zone_allocator<T> > { | 43 class ZoneDeque : public std::deque<T, zone_allocator<T>> { |
45 public: | 44 public: |
46 // Constructs an empty deque. | 45 // Constructs an empty deque. |
47 explicit ZoneDeque(Zone* zone) | 46 explicit ZoneDeque(Zone* zone) |
48 : std::deque<T, zone_allocator<T> >(zone_allocator<T>(zone)) {} | 47 : std::deque<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} |
49 }; | 48 }; |
50 | 49 |
51 | 50 |
| 51 // A wrapper subclass std::list to make it easy to construct one |
| 52 // that uses a zone allocator. |
| 53 // TODO(mstarzinger): This should be renamed to ZoneList once we got rid of our |
| 54 // own home-grown ZoneList that actually is a ZoneVector. |
| 55 template <typename T> |
| 56 class ZoneLinkedList : public std::list<T, zone_allocator<T>> { |
| 57 public: |
| 58 // Constructs an empty list. |
| 59 explicit ZoneLinkedList(Zone* zone) |
| 60 : std::list<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} |
| 61 }; |
| 62 |
| 63 |
52 // A wrapper subclass for std::queue to make it easy to construct one | 64 // A wrapper subclass for std::queue to make it easy to construct one |
53 // that uses a zone allocator. | 65 // that uses a zone allocator. |
54 template <typename T> | 66 template <typename T> |
55 class ZoneQueue : public std::queue<T, ZoneDeque<T>> { | 67 class ZoneQueue : public std::queue<T, ZoneDeque<T>> { |
56 public: | 68 public: |
57 // Constructs an empty queue. | 69 // Constructs an empty queue. |
58 explicit ZoneQueue(Zone* zone) | 70 explicit ZoneQueue(Zone* zone) |
59 : std::queue<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {} | 71 : std::queue<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {} |
60 }; | 72 }; |
61 | 73 |
(...skipping 10 matching lines...) Expand all Loading... |
72 | 84 |
73 | 85 |
74 // Typedefs to shorten commonly used vectors. | 86 // Typedefs to shorten commonly used vectors. |
75 typedef ZoneVector<bool> BoolVector; | 87 typedef ZoneVector<bool> BoolVector; |
76 typedef ZoneVector<int> IntVector; | 88 typedef ZoneVector<int> IntVector; |
77 | 89 |
78 } // namespace internal | 90 } // namespace internal |
79 } // namespace v8 | 91 } // namespace v8 |
80 | 92 |
81 #endif // V8_ZONE_CONTAINERS_H_ | 93 #endif // V8_ZONE_CONTAINERS_H_ |
OLD | NEW |