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_SRC_ZONE_ZONE_CONTAINERS_H_ |
6 #define V8_ZONE_CONTAINERS_H_ | 6 #define V8_SRC_ZONE_ZONE_CONTAINERS_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 #include <queue> | 11 #include <queue> |
12 #include <set> | 12 #include <set> |
13 #include <stack> | 13 #include <stack> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "src/zone-allocator.h" | 16 #include "src/zone/zone-allocator.h" |
17 | 17 |
18 namespace v8 { | 18 namespace v8 { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 // A wrapper subclass for std::vector to make it easy to construct one | 21 // A wrapper subclass for std::vector to make it easy to construct one |
22 // that uses a zone allocator. | 22 // that uses a zone allocator. |
23 template <typename T> | 23 template <typename T> |
24 class ZoneVector : public std::vector<T, zone_allocator<T>> { | 24 class ZoneVector : public std::vector<T, zone_allocator<T>> { |
25 public: | 25 public: |
26 // Constructs an empty vector. | 26 // Constructs an empty vector. |
27 explicit ZoneVector(Zone* zone) | 27 explicit ZoneVector(Zone* zone) |
28 : std::vector<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} | 28 : std::vector<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} |
29 | 29 |
30 // Constructs a new vector and fills it with {size} elements, each | 30 // Constructs a new vector and fills it with {size} elements, each |
31 // constructed via the default constructor. | 31 // constructed via the default constructor. |
32 ZoneVector(size_t size, Zone* zone) | 32 ZoneVector(size_t size, Zone* zone) |
33 : std::vector<T, zone_allocator<T>>(size, T(), zone_allocator<T>(zone)) {} | 33 : std::vector<T, zone_allocator<T>>(size, T(), zone_allocator<T>(zone)) {} |
34 | 34 |
35 // Constructs a new vector and fills it with {size} elements, each | 35 // Constructs a new vector and fills it with {size} elements, each |
36 // having the value {def}. | 36 // having the value {def}. |
37 ZoneVector(size_t size, T def, Zone* zone) | 37 ZoneVector(size_t size, T def, Zone* zone) |
38 : std::vector<T, zone_allocator<T>>(size, def, zone_allocator<T>(zone)) {} | 38 : std::vector<T, zone_allocator<T>>(size, def, zone_allocator<T>(zone)) {} |
39 }; | 39 }; |
40 | 40 |
41 | |
42 // A wrapper subclass std::deque to make it easy to construct one | 41 // A wrapper subclass std::deque to make it easy to construct one |
43 // that uses a zone allocator. | 42 // that uses a zone allocator. |
44 template <typename T> | 43 template <typename T> |
45 class ZoneDeque : public std::deque<T, zone_allocator<T>> { | 44 class ZoneDeque : public std::deque<T, zone_allocator<T>> { |
46 public: | 45 public: |
47 // Constructs an empty deque. | 46 // Constructs an empty deque. |
48 explicit ZoneDeque(Zone* zone) | 47 explicit ZoneDeque(Zone* zone) |
49 : std::deque<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} | 48 : std::deque<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} |
50 }; | 49 }; |
51 | 50 |
52 | |
53 // A wrapper subclass std::list to make it easy to construct one | 51 // A wrapper subclass std::list to make it easy to construct one |
54 // that uses a zone allocator. | 52 // that uses a zone allocator. |
55 // TODO(mstarzinger): This should be renamed to ZoneList once we got rid of our | 53 // TODO(mstarzinger): This should be renamed to ZoneList once we got rid of our |
56 // own home-grown ZoneList that actually is a ZoneVector. | 54 // own home-grown ZoneList that actually is a ZoneVector. |
57 template <typename T> | 55 template <typename T> |
58 class ZoneLinkedList : public std::list<T, zone_allocator<T>> { | 56 class ZoneLinkedList : public std::list<T, zone_allocator<T>> { |
59 public: | 57 public: |
60 // Constructs an empty list. | 58 // Constructs an empty list. |
61 explicit ZoneLinkedList(Zone* zone) | 59 explicit ZoneLinkedList(Zone* zone) |
62 : std::list<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} | 60 : std::list<T, zone_allocator<T>>(zone_allocator<T>(zone)) {} |
63 }; | 61 }; |
64 | 62 |
65 | |
66 // A wrapper subclass std::priority_queue to make it easy to construct one | 63 // A wrapper subclass std::priority_queue to make it easy to construct one |
67 // that uses a zone allocator. | 64 // that uses a zone allocator. |
68 template <typename T, typename Compare = std::less<T>> | 65 template <typename T, typename Compare = std::less<T>> |
69 class ZonePriorityQueue | 66 class ZonePriorityQueue |
70 : public std::priority_queue<T, ZoneVector<T>, Compare> { | 67 : public std::priority_queue<T, ZoneVector<T>, Compare> { |
71 public: | 68 public: |
72 // Constructs an empty list. | 69 // Constructs an empty list. |
73 explicit ZonePriorityQueue(Zone* zone) | 70 explicit ZonePriorityQueue(Zone* zone) |
74 : std::priority_queue<T, ZoneVector<T>, Compare>(Compare(), | 71 : std::priority_queue<T, ZoneVector<T>, Compare>(Compare(), |
75 ZoneVector<T>(zone)) {} | 72 ZoneVector<T>(zone)) {} |
76 }; | 73 }; |
77 | 74 |
78 | |
79 // A wrapper subclass for std::queue to make it easy to construct one | 75 // A wrapper subclass for std::queue to make it easy to construct one |
80 // that uses a zone allocator. | 76 // that uses a zone allocator. |
81 template <typename T> | 77 template <typename T> |
82 class ZoneQueue : public std::queue<T, ZoneDeque<T>> { | 78 class ZoneQueue : public std::queue<T, ZoneDeque<T>> { |
83 public: | 79 public: |
84 // Constructs an empty queue. | 80 // Constructs an empty queue. |
85 explicit ZoneQueue(Zone* zone) | 81 explicit ZoneQueue(Zone* zone) |
86 : std::queue<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {} | 82 : std::queue<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {} |
87 }; | 83 }; |
88 | 84 |
89 | |
90 // A wrapper subclass for std::stack to make it easy to construct one that uses | 85 // A wrapper subclass for std::stack to make it easy to construct one that uses |
91 // a zone allocator. | 86 // a zone allocator. |
92 template <typename T> | 87 template <typename T> |
93 class ZoneStack : public std::stack<T, ZoneDeque<T>> { | 88 class ZoneStack : public std::stack<T, ZoneDeque<T>> { |
94 public: | 89 public: |
95 // Constructs an empty stack. | 90 // Constructs an empty stack. |
96 explicit ZoneStack(Zone* zone) | 91 explicit ZoneStack(Zone* zone) |
97 : std::stack<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {} | 92 : std::stack<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {} |
98 }; | 93 }; |
99 | 94 |
100 | |
101 // A wrapper subclass for std::set to make it easy to construct one that uses | 95 // A wrapper subclass for std::set to make it easy to construct one that uses |
102 // a zone allocator. | 96 // a zone allocator. |
103 template <typename K, typename Compare = std::less<K>> | 97 template <typename K, typename Compare = std::less<K>> |
104 class ZoneSet : public std::set<K, Compare, zone_allocator<K>> { | 98 class ZoneSet : public std::set<K, Compare, zone_allocator<K>> { |
105 public: | 99 public: |
106 // Constructs an empty set. | 100 // Constructs an empty set. |
107 explicit ZoneSet(Zone* zone) | 101 explicit ZoneSet(Zone* zone) |
108 : std::set<K, Compare, zone_allocator<K>>(Compare(), | 102 : std::set<K, Compare, zone_allocator<K>>(Compare(), |
109 zone_allocator<K>(zone)) {} | 103 zone_allocator<K>(zone)) {} |
110 }; | 104 }; |
111 | 105 |
112 | |
113 // A wrapper subclass for std::map to make it easy to construct one that uses | 106 // A wrapper subclass for std::map to make it easy to construct one that uses |
114 // a zone allocator. | 107 // a zone allocator. |
115 template <typename K, typename V, typename Compare = std::less<K>> | 108 template <typename K, typename V, typename Compare = std::less<K>> |
116 class ZoneMap | 109 class ZoneMap |
117 : public std::map<K, V, Compare, zone_allocator<std::pair<const K, V>>> { | 110 : public std::map<K, V, Compare, zone_allocator<std::pair<const K, V>>> { |
118 public: | 111 public: |
119 // Constructs an empty map. | 112 // Constructs an empty map. |
120 explicit ZoneMap(Zone* zone) | 113 explicit ZoneMap(Zone* zone) |
121 : std::map<K, V, Compare, zone_allocator<std::pair<const K, V>>>( | 114 : std::map<K, V, Compare, zone_allocator<std::pair<const K, V>>>( |
122 Compare(), zone_allocator<std::pair<const K, V>>(zone)) {} | 115 Compare(), zone_allocator<std::pair<const K, V>>(zone)) {} |
(...skipping 12 matching lines...) Expand all Loading... |
135 Compare(), zone_allocator<std::pair<const K, V>>(zone)) {} | 128 Compare(), zone_allocator<std::pair<const K, V>>(zone)) {} |
136 }; | 129 }; |
137 | 130 |
138 // Typedefs to shorten commonly used vectors. | 131 // Typedefs to shorten commonly used vectors. |
139 typedef ZoneVector<bool> BoolVector; | 132 typedef ZoneVector<bool> BoolVector; |
140 typedef ZoneVector<int> IntVector; | 133 typedef ZoneVector<int> IntVector; |
141 | 134 |
142 } // namespace internal | 135 } // namespace internal |
143 } // namespace v8 | 136 } // namespace v8 |
144 | 137 |
145 #endif // V8_ZONE_CONTAINERS_H_ | 138 #endif // V8_SRC_ZONE_ZONE_CONTAINERS_H_ |
OLD | NEW |