| 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 <queue> | 9 #include <queue> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "src/zone-allocator.h" | 12 #include "src/zone-allocator.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 // A wrapper subclass for std::vector to make it easy to construct one | 17 // A wrapper subclass for std::vector to make it easy to construct one |
| 18 // that uses a zone allocator. | 18 // that uses a zone allocator. |
| 19 template <typename T> | 19 template <typename T> |
| 20 class ZoneVector : public std::vector<T, zone_allocator<T> > { | 20 class ZoneVector : public std::vector<T, zone_allocator<T> > { |
| 21 public: | 21 public: |
| 22 // Constructs an empty vector. | 22 // Constructs an empty vector. |
| 23 explicit ZoneVector(Zone* zone) | 23 explicit ZoneVector(Zone* zone) |
| 24 : std::vector<T, zone_allocator<T> >(zone_allocator<T>(zone)) {} | 24 : std::vector<T, zone_allocator<T> >(zone_allocator<T>(zone)) {} |
| 25 | 25 |
| 26 // Constructs a new vector and fills it with {size} elements, each | 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)) { |
| 30 } |
| 31 |
| 32 // Constructs a new vector and fills it with {size} elements, each |
| 27 // having the value {def}. | 33 // having the value {def}. |
| 28 ZoneVector(int size, T def, Zone* zone) | 34 ZoneVector(int size, T def, Zone* zone) |
| 29 : std::vector<T, zone_allocator<T> >(size, def, zone_allocator<T>(zone)) { | 35 : std::vector<T, zone_allocator<T> >(size, def, zone_allocator<T>(zone)) { |
| 30 } | 36 } |
| 31 }; | 37 }; |
| 32 | 38 |
| 33 // A wrapper subclass std::deque to make it easy to construct one | 39 // A wrapper subclass std::deque to make it easy to construct one |
| 34 // that uses a zone allocator. | 40 // that uses a zone allocator. |
| 35 template <typename T> | 41 template <typename T> |
| 36 class ZoneDeque : public std::deque<T, zone_allocator<T> > { | 42 class ZoneDeque : public std::deque<T, zone_allocator<T> > { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 49 : std::queue<T, std::deque<T, zone_allocator<T> > >( | 55 : std::queue<T, std::deque<T, zone_allocator<T> > >( |
| 50 std::deque<T, zone_allocator<T> >(zone_allocator<T>(zone))) {} | 56 std::deque<T, zone_allocator<T> >(zone_allocator<T>(zone))) {} |
| 51 }; | 57 }; |
| 52 | 58 |
| 53 // Typedefs to shorten commonly used vectors. | 59 // Typedefs to shorten commonly used vectors. |
| 54 typedef ZoneVector<bool> BoolVector; | 60 typedef ZoneVector<bool> BoolVector; |
| 55 typedef ZoneVector<int> IntVector; | 61 typedef ZoneVector<int> IntVector; |
| 56 } } // namespace v8::internal | 62 } } // namespace v8::internal |
| 57 | 63 |
| 58 #endif // V8_ZONE_CONTAINERS_H_ | 64 #endif // V8_ZONE_CONTAINERS_H_ |
| OLD | NEW |