Chromium Code Reviews| 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 <stack> | |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "src/zone-allocator.h" | 13 #include "src/zone-allocator.h" |
| 13 | 14 |
| 14 namespace v8 { | 15 namespace v8 { |
| 15 namespace internal { | 16 namespace internal { |
| 16 | 17 |
| 17 // A wrapper subclass for std::vector to make it easy to construct one | 18 // A wrapper subclass for std::vector to make it easy to construct one |
| 18 // that uses a zone allocator. | 19 // that uses a zone allocator. |
| 19 template <typename T> | 20 template <typename T> |
| 20 class ZoneVector : public std::vector<T, zone_allocator<T> > { | 21 class ZoneVector : public std::vector<T, zone_allocator<T> > { |
| 21 public: | 22 public: |
| 22 // Constructs an empty vector. | 23 // Constructs an empty vector. |
| 23 explicit ZoneVector(Zone* zone) | 24 explicit ZoneVector(Zone* zone) |
| 24 : std::vector<T, zone_allocator<T> >(zone_allocator<T>(zone)) {} | 25 : std::vector<T, zone_allocator<T> >(zone_allocator<T>(zone)) {} |
| 25 | 26 |
| 26 // Constructs a new vector and fills it with {size} elements, each | 27 // Constructs a new vector and fills it with {size} elements, each |
| 27 // constructed via the default constructor. | 28 // constructed via the default constructor. |
| 28 ZoneVector(int size, Zone* zone) | 29 ZoneVector(int size, Zone* zone) |
| 29 : std::vector<T, zone_allocator<T> >(size, T(), zone_allocator<T>(zone)) { | 30 : std::vector<T, zone_allocator<T> >(size, T(), zone_allocator<T>(zone)) { |
| 30 } | 31 } |
| 31 | 32 |
| 32 // Constructs a new vector and fills it with {size} elements, each | 33 // Constructs a new vector and fills it with {size} elements, each |
| 33 // having the value {def}. | 34 // having the value {def}. |
| 34 ZoneVector(int size, T def, Zone* zone) | 35 ZoneVector(int size, T def, Zone* zone) |
| 35 : 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)) { |
| 36 } | 37 } |
| 37 }; | 38 }; |
| 38 | 39 |
| 40 | |
| 39 // 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 |
| 40 // that uses a zone allocator. | 42 // that uses a zone allocator. |
| 41 template <typename T> | 43 template <typename T> |
| 42 class ZoneDeque : public std::deque<T, zone_allocator<T> > { | 44 class ZoneDeque : public std::deque<T, zone_allocator<T> > { |
| 43 public: | 45 public: |
| 46 // Constructs an empty deque. | |
| 44 explicit ZoneDeque(Zone* zone) | 47 explicit ZoneDeque(Zone* zone) |
| 45 : std::deque<T, zone_allocator<T> >(zone_allocator<T>(zone)) {} | 48 : std::deque<T, zone_allocator<T> >(zone_allocator<T>(zone)) {} |
| 49 | |
| 50 // Constructs a new deque and fills it with {size} elements, each constructed | |
| 51 // via the default constructor. | |
| 52 ZoneDeque(int size, Zone* zone) | |
|
dcarney
2014/11/13 10:42:15
i really think we should be taking size_t here - i
Benedikt Meurer
2014/11/13 10:50:34
Ups that was dead code anyway.
| |
| 53 : std::deque<T, zone_allocator<T>>(bit_cast<unsigned>(size), T(), | |
| 54 zone_allocator<T>(zone)) {} | |
| 46 }; | 55 }; |
| 47 | 56 |
| 57 | |
| 48 // A wrapper subclass for std::queue to make it easy to construct one | 58 // A wrapper subclass for std::queue to make it easy to construct one |
| 49 // that uses a zone allocator. | 59 // that uses a zone allocator. |
| 50 template <typename T> | 60 template <typename T> |
| 51 class ZoneQueue : public std::queue<T, std::deque<T, zone_allocator<T> > > { | 61 class ZoneQueue : public std::queue<T, ZoneDeque<T>> { |
| 52 public: | 62 public: |
| 53 // Constructs an empty queue. | 63 // Constructs an empty queue. |
| 54 explicit ZoneQueue(Zone* zone) | 64 explicit ZoneQueue(Zone* zone) |
| 55 : std::queue<T, std::deque<T, zone_allocator<T> > >( | 65 : std::queue<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {} |
| 56 std::deque<T, zone_allocator<T> >(zone_allocator<T>(zone))) {} | |
| 57 }; | 66 }; |
| 58 | 67 |
| 68 | |
| 69 // A wrapper subclass for std::stack to make it easy to construct one that uses | |
| 70 // a zone allocator. | |
| 71 template <typename T> | |
| 72 class ZoneStack : public std::stack<T, ZoneDeque<T>> { | |
| 73 public: | |
| 74 // Constructs an empty stack. | |
| 75 explicit ZoneStack(Zone* zone) | |
| 76 : std::stack<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {} | |
| 77 }; | |
| 78 | |
| 79 | |
| 59 // Typedefs to shorten commonly used vectors. | 80 // Typedefs to shorten commonly used vectors. |
| 60 typedef ZoneVector<bool> BoolVector; | 81 typedef ZoneVector<bool> BoolVector; |
| 61 typedef ZoneVector<int> IntVector; | 82 typedef ZoneVector<int> IntVector; |
| 62 } } // namespace v8::internal | 83 |
| 84 } // namespace internal | |
| 85 } // namespace v8 | |
| 63 | 86 |
| 64 #endif // V8_ZONE_CONTAINERS_H_ | 87 #endif // V8_ZONE_CONTAINERS_H_ |
| OLD | NEW |