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

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

Issue 2646873004: Enable emplace_back for zone containers (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « src/wasm/wasm-text.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_ZONE_ALLOCATOR_H_ 5 #ifndef V8_ZONE_ZONE_ALLOCATOR_H_
6 #define V8_ZONE_ZONE_ALLOCATOR_H_ 6 #define V8_ZONE_ZONE_ALLOCATOR_H_
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/zone/zone.h" 9 #include "src/zone/zone.h"
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 pointer allocate(size_type n, const void* hint = 0) { 42 pointer allocate(size_type n, const void* hint = 0) {
43 return static_cast<pointer>( 43 return static_cast<pointer>(
44 zone_->NewArray<value_type>(static_cast<int>(n))); 44 zone_->NewArray<value_type>(static_cast<int>(n)));
45 } 45 }
46 void deallocate(pointer p, size_type) { /* noop for Zones */ 46 void deallocate(pointer p, size_type) { /* noop for Zones */
47 } 47 }
48 48
49 size_type max_size() const throw() { 49 size_type max_size() const throw() {
50 return std::numeric_limits<int>::max() / sizeof(value_type); 50 return std::numeric_limits<int>::max() / sizeof(value_type);
51 } 51 }
52 void construct(pointer p, const T& val) { 52 template <typename U, typename... Args>
53 new (static_cast<void*>(p)) T(val); 53 void construct(U* p, Args&&... args) {
54 void* v_p = const_cast<void*>(static_cast<const void*>(p));
55 new (v_p) U(std::forward<Args>(args)...);
54 } 56 }
55 void destroy(pointer p) { p->~T(); } 57 template <typename U>
58 void destroy(U* p) {
59 p->~U();
60 }
56 61
57 bool operator==(zone_allocator const& other) const { 62 bool operator==(zone_allocator const& other) const {
58 return zone_ == other.zone_; 63 return zone_ == other.zone_;
59 } 64 }
60 bool operator!=(zone_allocator const& other) const { 65 bool operator!=(zone_allocator const& other) const {
61 return zone_ != other.zone_; 66 return zone_ != other.zone_;
62 } 67 }
63 68
64 Zone* zone() { return zone_; } 69 Zone* zone() { return zone_; }
65 70
66 private: 71 private:
67 Zone* zone_; 72 Zone* zone_;
68 }; 73 };
69 74
70 typedef zone_allocator<bool> ZoneBoolAllocator; 75 typedef zone_allocator<bool> ZoneBoolAllocator;
71 typedef zone_allocator<int> ZoneIntAllocator; 76 typedef zone_allocator<int> ZoneIntAllocator;
72 } // namespace internal 77 } // namespace internal
73 } // namespace v8 78 } // namespace v8
74 79
75 #endif // V8_ZONE_ZONE_ALLOCATOR_H_ 80 #endif // V8_ZONE_ZONE_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « src/wasm/wasm-text.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698