OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_ZONE_H_ | 5 #ifndef V8_ZONE_ZONE_H_ |
6 #define V8_ZONE_ZONE_H_ | 6 #define V8_ZONE_ZONE_H_ |
7 | 7 |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Zone. ZoneLists cannot be deleted individually; you can delete all | 153 // Zone. ZoneLists cannot be deleted individually; you can delete all |
154 // objects in the Zone by calling Zone::DeleteAll(). | 154 // objects in the Zone by calling Zone::DeleteAll(). |
155 template <typename T> | 155 template <typename T> |
156 class ZoneList final : public List<T, ZoneAllocationPolicy> { | 156 class ZoneList final : public List<T, ZoneAllocationPolicy> { |
157 public: | 157 public: |
158 // Construct a new ZoneList with the given capacity; the length is | 158 // Construct a new ZoneList with the given capacity; the length is |
159 // always zero. The capacity must be non-negative. | 159 // always zero. The capacity must be non-negative. |
160 ZoneList(int capacity, Zone* zone) | 160 ZoneList(int capacity, Zone* zone) |
161 : List<T, ZoneAllocationPolicy>(capacity, ZoneAllocationPolicy(zone)) {} | 161 : List<T, ZoneAllocationPolicy>(capacity, ZoneAllocationPolicy(zone)) {} |
162 | 162 |
| 163 // Construct a new ZoneList from a std::initializer_list |
| 164 ZoneList(std::initializer_list<T> list, Zone* zone) |
| 165 : List<T, ZoneAllocationPolicy>(static_cast<int>(list.size()), |
| 166 ZoneAllocationPolicy(zone)) { |
| 167 for (auto& i : list) Add(i, zone); |
| 168 } |
| 169 |
163 void* operator new(size_t size, Zone* zone) { return zone->New(size); } | 170 void* operator new(size_t size, Zone* zone) { return zone->New(size); } |
164 | 171 |
165 // Construct a new ZoneList by copying the elements of the given ZoneList. | 172 // Construct a new ZoneList by copying the elements of the given ZoneList. |
166 ZoneList(const ZoneList<T>& other, Zone* zone) | 173 ZoneList(const ZoneList<T>& other, Zone* zone) |
167 : List<T, ZoneAllocationPolicy>(other.length(), | 174 : List<T, ZoneAllocationPolicy>(other.length(), |
168 ZoneAllocationPolicy(zone)) { | 175 ZoneAllocationPolicy(zone)) { |
169 AddAll(other, zone); | 176 AddAll(other, zone); |
170 } | 177 } |
171 | 178 |
172 // We add some convenience wrappers so that we can pass in a Zone | 179 // We add some convenience wrappers so that we can pass in a Zone |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 230 |
224 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; | 231 typedef base::PointerTemplateHashMapImpl<ZoneAllocationPolicy> ZoneHashMap; |
225 | 232 |
226 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> | 233 typedef base::CustomMatcherTemplateHashMapImpl<ZoneAllocationPolicy> |
227 CustomMatcherZoneHashMap; | 234 CustomMatcherZoneHashMap; |
228 | 235 |
229 } // namespace internal | 236 } // namespace internal |
230 } // namespace v8 | 237 } // namespace v8 |
231 | 238 |
232 #endif // V8_ZONE_ZONE_H_ | 239 #endif // V8_ZONE_ZONE_H_ |
OLD | NEW |