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

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

Issue 2344143003: Moved zones and zone related stuff in its own directory. (Closed)
Patch Set: Moved zones and zone related stuff into it's own folder Created 4 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
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_ALLOCATOR_H_ 5 #ifndef V8_ZONE_ALLOCATOR_H_
6 #define V8_ZONE_ALLOCATOR_H_ 6 #define V8_ZONE_ALLOCATOR_H_
jochen (gone - plz use gerrit) 2016/09/16 13:14:52 same here (and all files you've moved)
heimbuef 2016/09/16 13:49:53 Done.
7 7
8 #include <limits> 8 #include <limits>
9 9
10 #include "src/zone.h" 10 #include "src/zone/zone.h"
11 11
12 namespace v8 { 12 namespace v8 {
13 namespace internal { 13 namespace internal {
14 14
15 template<typename T> 15 template <typename T>
16 class zone_allocator { 16 class zone_allocator {
17 public: 17 public:
18 typedef T* pointer; 18 typedef T* pointer;
19 typedef const T* const_pointer; 19 typedef const T* const_pointer;
20 typedef T& reference; 20 typedef T& reference;
21 typedef const T& const_reference; 21 typedef const T& const_reference;
22 typedef T value_type; 22 typedef T value_type;
23 typedef size_t size_type; 23 typedef size_t size_type;
24 typedef ptrdiff_t difference_type; 24 typedef ptrdiff_t difference_type;
25 template<class O> struct rebind { 25 template <class O>
26 struct rebind {
26 typedef zone_allocator<O> other; 27 typedef zone_allocator<O> other;
27 }; 28 };
28 29
29 explicit zone_allocator(Zone* zone) throw() : zone_(zone) {} 30 explicit zone_allocator(Zone* zone) throw() : zone_(zone) {}
30 explicit zone_allocator(const zone_allocator& other) throw() 31 explicit zone_allocator(const zone_allocator& other) throw()
31 : zone_(other.zone_) {} 32 : zone_(other.zone_) {}
32 template<typename U> zone_allocator(const zone_allocator<U>& other) throw() 33 template <typename U>
33 : zone_(other.zone_) {} 34 zone_allocator(const zone_allocator<U>& other) throw() : zone_(other.zone_) {}
34 template<typename U> friend class zone_allocator; 35 template <typename U>
36 friend class zone_allocator;
35 37
36 pointer address(reference x) const {return &x;} 38 pointer address(reference x) const { return &x; }
37 const_pointer address(const_reference x) const {return &x;} 39 const_pointer address(const_reference x) const { return &x; }
38 40
39 pointer allocate(size_type n, const void* hint = 0) { 41 pointer allocate(size_type n, const void* hint = 0) {
40 return static_cast<pointer>(zone_->NewArray<value_type>( 42 return static_cast<pointer>(
41 static_cast<int>(n))); 43 zone_->NewArray<value_type>(static_cast<int>(n)));
42 } 44 }
43 void deallocate(pointer p, size_type) { /* noop for Zones */ } 45 void deallocate(pointer p, size_type) { /* noop for Zones */
46 }
44 47
45 size_type max_size() const throw() { 48 size_type max_size() const throw() {
46 return std::numeric_limits<int>::max() / sizeof(value_type); 49 return std::numeric_limits<int>::max() / sizeof(value_type);
47 } 50 }
48 void construct(pointer p, const T& val) { 51 void construct(pointer p, const T& val) {
49 new(static_cast<void*>(p)) T(val); 52 new (static_cast<void*>(p)) T(val);
50 } 53 }
51 void destroy(pointer p) { p->~T(); } 54 void destroy(pointer p) { p->~T(); }
52 55
53 bool operator==(zone_allocator const& other) const { 56 bool operator==(zone_allocator const& other) const {
54 return zone_ == other.zone_; 57 return zone_ == other.zone_;
55 } 58 }
56 bool operator!=(zone_allocator const& other) const { 59 bool operator!=(zone_allocator const& other) const {
57 return zone_ != other.zone_; 60 return zone_ != other.zone_;
58 } 61 }
59 62
60 Zone* zone() { return zone_; } 63 Zone* zone() { return zone_; }
61 64
62 private: 65 private:
63 zone_allocator(); 66 zone_allocator();
64 Zone* zone_; 67 Zone* zone_;
65 }; 68 };
66 69
67 typedef zone_allocator<bool> ZoneBoolAllocator; 70 typedef zone_allocator<bool> ZoneBoolAllocator;
68 typedef zone_allocator<int> ZoneIntAllocator; 71 typedef zone_allocator<int> ZoneIntAllocator;
69 } // namespace internal 72 } // namespace internal
70 } // namespace v8 73 } // namespace v8
71 74
72 #endif // V8_ZONE_ALLOCATOR_H_ 75 #endif // V8_ZONE_ALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698