Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: src/zone-containers.h

Issue 505133003: Introduce subclass wrappers for STL containers that make them a lot easier (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/verifier.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
9 #include <queue>
8 #include <vector> 10 #include <vector>
9 11
10 #include "src/zone-allocator.h" 12 #include "src/zone-allocator.h"
11 13
12 namespace v8 { 14 namespace v8 {
13 namespace internal { 15 namespace internal {
14 16
15 typedef std::vector<bool, ZoneBoolAllocator> BoolVector; 17 // A wrapper subclass for std::vector to make it easy to construct one
18 // that uses a zone allocator.
19 template <typename T>
20 class ZoneVector : public std::vector<T, zone_allocator<T>> {
21 public:
22 // Constructs an empty vector.
23 explicit ZoneVector(Zone* zone)
24 : std::vector<T, zone_allocator<T>>(zone_allocator<T>(zone)) {}
16 25
17 typedef std::vector<int, ZoneIntAllocator> IntVector; 26 // Constructs a new vector and fills it with {size} elements, each
18 typedef IntVector::iterator IntVectorIter; 27 // having the value {def}.
19 typedef IntVector::reverse_iterator IntVectorRIter; 28 ZoneVector(int size, T def, Zone* zone)
29 : std::vector<T, zone_allocator<T>>(size, def, zone_allocator<T>(zone)) {}
30 };
20 31
32 // A wrapper subclass std::deque to make it easy to construct one
33 // that uses a zone allocator.
34 template <typename T>
35 class ZoneDeque : public std::deque<T, zone_allocator<T>> {
36 public:
37 explicit ZoneDeque(Zone* zone)
38 : std::deque<T, zone_allocator<T>>(zone_allocator<T>(zone)) {}
39 };
40
41 // A wrapper subclass for std::queue to make it easy to construct one
42 // that uses a zone allocator.
43 template <typename T>
44 class ZoneQueue : public std::queue<T, std::deque<T, zone_allocator<T>>> {
45 public:
46 // Constructs an empty queue.
47 explicit ZoneQueue(Zone* zone)
48 : std::queue<T, std::deque<T, zone_allocator<T>>>(
49 std::deque<T, zone_allocator<T>>(zone_allocator<T>(zone))) {}
50 };
51
52 // Typedefs to shorten commonly used vectors.
53 typedef ZoneVector<bool> BoolVector;
54 typedef ZoneVector<int> IntVector;
21 } } // namespace v8::internal 55 } } // namespace v8::internal
22 56
23 #endif // V8_ZONE_CONTAINERS_H_ 57 #endif // V8_ZONE_CONTAINERS_H_
OLDNEW
« no previous file with comments | « src/compiler/verifier.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698