2014-02-07 11:55:11 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2014-02-07 11:55:11 +00:00
|
|
|
|
|
|
|
#ifndef V8_ZONE_CONTAINERS_H_
|
|
|
|
#define V8_ZONE_CONTAINERS_H_
|
|
|
|
|
2014-08-26 13:09:08 +00:00
|
|
|
#include <deque>
|
2014-12-02 15:56:22 +00:00
|
|
|
#include <list>
|
2015-01-31 14:34:51 +00:00
|
|
|
#include <map>
|
2014-08-26 13:09:08 +00:00
|
|
|
#include <queue>
|
2015-01-31 14:34:51 +00:00
|
|
|
#include <set>
|
2014-11-17 12:12:24 +00:00
|
|
|
#include <stack>
|
2014-06-20 08:40:11 +00:00
|
|
|
#include <vector>
|
2014-02-07 11:55:11 +00:00
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/zone-allocator.h"
|
2014-02-07 11:55:11 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2014-08-26 13:09:08 +00:00
|
|
|
// A wrapper subclass for std::vector to make it easy to construct one
|
|
|
|
// that uses a zone allocator.
|
|
|
|
template <typename T>
|
2014-12-02 15:56:22 +00:00
|
|
|
class ZoneVector : public std::vector<T, zone_allocator<T>> {
|
2014-08-26 13:09:08 +00:00
|
|
|
public:
|
|
|
|
// Constructs an empty vector.
|
|
|
|
explicit ZoneVector(Zone* zone)
|
2014-12-02 15:56:22 +00:00
|
|
|
: std::vector<T, zone_allocator<T>>(zone_allocator<T>(zone)) {}
|
2014-08-26 13:09:08 +00:00
|
|
|
|
2014-10-14 08:51:22 +00:00
|
|
|
// Constructs a new vector and fills it with {size} elements, each
|
|
|
|
// constructed via the default constructor.
|
2015-01-08 14:13:18 +00:00
|
|
|
ZoneVector(size_t size, Zone* zone)
|
2014-12-02 15:56:22 +00:00
|
|
|
: std::vector<T, zone_allocator<T>>(size, T(), zone_allocator<T>(zone)) {}
|
2014-10-14 08:51:22 +00:00
|
|
|
|
2014-08-26 13:09:08 +00:00
|
|
|
// Constructs a new vector and fills it with {size} elements, each
|
|
|
|
// having the value {def}.
|
2015-01-08 14:13:18 +00:00
|
|
|
ZoneVector(size_t size, T def, Zone* zone)
|
2014-12-02 15:56:22 +00:00
|
|
|
: std::vector<T, zone_allocator<T>>(size, def, zone_allocator<T>(zone)) {}
|
2014-08-26 13:09:08 +00:00
|
|
|
};
|
|
|
|
|
2014-11-17 12:12:24 +00:00
|
|
|
|
2014-08-26 13:09:08 +00:00
|
|
|
// A wrapper subclass std::deque to make it easy to construct one
|
|
|
|
// that uses a zone allocator.
|
|
|
|
template <typename T>
|
2014-12-02 15:56:22 +00:00
|
|
|
class ZoneDeque : public std::deque<T, zone_allocator<T>> {
|
2014-08-26 13:09:08 +00:00
|
|
|
public:
|
2014-11-17 12:12:24 +00:00
|
|
|
// Constructs an empty deque.
|
2014-08-26 13:09:08 +00:00
|
|
|
explicit ZoneDeque(Zone* zone)
|
2014-12-02 15:56:22 +00:00
|
|
|
: std::deque<T, zone_allocator<T>>(zone_allocator<T>(zone)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A wrapper subclass std::list to make it easy to construct one
|
|
|
|
// that uses a zone allocator.
|
|
|
|
// TODO(mstarzinger): This should be renamed to ZoneList once we got rid of our
|
|
|
|
// own home-grown ZoneList that actually is a ZoneVector.
|
|
|
|
template <typename T>
|
|
|
|
class ZoneLinkedList : public std::list<T, zone_allocator<T>> {
|
|
|
|
public:
|
|
|
|
// Constructs an empty list.
|
|
|
|
explicit ZoneLinkedList(Zone* zone)
|
|
|
|
: std::list<T, zone_allocator<T>>(zone_allocator<T>(zone)) {}
|
2014-08-26 13:09:08 +00:00
|
|
|
};
|
|
|
|
|
2014-11-17 12:12:24 +00:00
|
|
|
|
2015-04-22 19:39:56 +00:00
|
|
|
// A wrapper subclass std::priority_queue to make it easy to construct one
|
|
|
|
// that uses a zone allocator.
|
|
|
|
template <typename T, typename Compare = std::less<T>>
|
2015-06-11 05:14:59 +00:00
|
|
|
class ZonePriorityQueue
|
|
|
|
: public std::priority_queue<T, ZoneVector<T>, Compare> {
|
2015-04-22 19:39:56 +00:00
|
|
|
public:
|
|
|
|
// Constructs an empty list.
|
|
|
|
explicit ZonePriorityQueue(Zone* zone)
|
2015-06-11 05:14:59 +00:00
|
|
|
: std::priority_queue<T, ZoneVector<T>, Compare>(Compare(),
|
|
|
|
ZoneVector<T>(zone)) {}
|
2015-04-22 19:39:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-26 13:09:08 +00:00
|
|
|
// A wrapper subclass for std::queue to make it easy to construct one
|
|
|
|
// that uses a zone allocator.
|
|
|
|
template <typename T>
|
2014-11-17 12:12:24 +00:00
|
|
|
class ZoneQueue : public std::queue<T, ZoneDeque<T>> {
|
2014-08-26 13:09:08 +00:00
|
|
|
public:
|
|
|
|
// Constructs an empty queue.
|
|
|
|
explicit ZoneQueue(Zone* zone)
|
2014-11-17 12:12:24 +00:00
|
|
|
: std::queue<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {}
|
2014-08-26 13:09:08 +00:00
|
|
|
};
|
|
|
|
|
2014-11-17 12:12:24 +00:00
|
|
|
|
|
|
|
// A wrapper subclass for std::stack to make it easy to construct one that uses
|
|
|
|
// a zone allocator.
|
|
|
|
template <typename T>
|
|
|
|
class ZoneStack : public std::stack<T, ZoneDeque<T>> {
|
|
|
|
public:
|
|
|
|
// Constructs an empty stack.
|
|
|
|
explicit ZoneStack(Zone* zone)
|
|
|
|
: std::stack<T, ZoneDeque<T>>(ZoneDeque<T>(zone)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-01-31 14:34:51 +00:00
|
|
|
// A wrapper subclass for std::set to make it easy to construct one that uses
|
|
|
|
// a zone allocator.
|
|
|
|
template <typename K, typename Compare = std::less<K>>
|
|
|
|
class ZoneSet : public std::set<K, Compare, zone_allocator<K>> {
|
|
|
|
public:
|
|
|
|
// Constructs an empty set.
|
|
|
|
explicit ZoneSet(Zone* zone)
|
|
|
|
: std::set<K, Compare, zone_allocator<K>>(Compare(),
|
|
|
|
zone_allocator<K>(zone)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A wrapper subclass for std::map to make it easy to construct one that uses
|
|
|
|
// a zone allocator.
|
|
|
|
template <typename K, typename V, typename Compare = std::less<K>>
|
|
|
|
class ZoneMap
|
|
|
|
: public std::map<K, V, Compare, zone_allocator<std::pair<K, V>>> {
|
|
|
|
public:
|
|
|
|
// Constructs an empty map.
|
|
|
|
explicit ZoneMap(Zone* zone)
|
|
|
|
: std::map<K, V, Compare, zone_allocator<std::pair<K, V>>>(
|
|
|
|
Compare(), zone_allocator<std::pair<K, V>>(zone)) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-26 13:09:08 +00:00
|
|
|
// Typedefs to shorten commonly used vectors.
|
|
|
|
typedef ZoneVector<bool> BoolVector;
|
|
|
|
typedef ZoneVector<int> IntVector;
|
2014-11-17 12:12:24 +00:00
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2014-02-07 11:55:11 +00:00
|
|
|
|
|
|
|
#endif // V8_ZONE_CONTAINERS_H_
|