OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 #ifndef TerminatedArray_h | 4 #ifndef TerminatedArray_h |
5 #define TerminatedArray_h | 5 #define TerminatedArray_h |
6 | 6 |
7 #include "wtf/Allocator.h" | 7 #include "wtf/Allocator.h" |
8 #include "wtf/PtrUtil.h" | 8 #include "wtf/PtrUtil.h" |
9 #include "wtf/allocator/Partitions.h" | 9 #include "wtf/allocator/Partitions.h" |
10 #include <memory> | 10 #include <memory> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // Allocator describes how TerminatedArrayBuilder should create new instances | 83 // Allocator describes how TerminatedArrayBuilder should create new instances |
84 // of TerminateArray and manage their lifetimes. | 84 // of TerminateArray and manage their lifetimes. |
85 struct Allocator { | 85 struct Allocator { |
86 STATIC_ONLY(Allocator); | 86 STATIC_ONLY(Allocator); |
87 using PassPtr = std::unique_ptr<TerminatedArray>; | 87 using PassPtr = std::unique_ptr<TerminatedArray>; |
88 using Ptr = std::unique_ptr<TerminatedArray>; | 88 using Ptr = std::unique_ptr<TerminatedArray>; |
89 | 89 |
90 static PassPtr release(Ptr& ptr) { return ptr.release(); } | 90 static PassPtr release(Ptr& ptr) { return ptr.release(); } |
91 | 91 |
92 static PassPtr create(size_t capacity) { | 92 static PassPtr create(size_t capacity) { |
93 return wrapUnique( | 93 return WTF::wrapUnique( |
94 static_cast<TerminatedArray*>(WTF::Partitions::fastMalloc( | 94 static_cast<TerminatedArray*>(WTF::Partitions::fastMalloc( |
95 capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); | 95 capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); |
96 } | 96 } |
97 | 97 |
98 static PassPtr resize(Ptr ptr, size_t capacity) { | 98 static PassPtr resize(Ptr ptr, size_t capacity) { |
99 return wrapUnique(static_cast<TerminatedArray*>( | 99 return WTF::wrapUnique(static_cast<TerminatedArray*>( |
100 WTF::Partitions::fastRealloc(ptr.release(), capacity * sizeof(T), | 100 WTF::Partitions::fastRealloc(ptr.release(), capacity * sizeof(T), |
101 WTF_HEAP_PROFILER_TYPE_NAME(T)))); | 101 WTF_HEAP_PROFILER_TYPE_NAME(T)))); |
102 } | 102 } |
103 }; | 103 }; |
104 | 104 |
105 // Prohibit construction. Allocator makes TerminatedArray instances for | 105 // Prohibit construction. Allocator makes TerminatedArray instances for |
106 // TerminatedArrayBuilder by pointer casting. | 106 // TerminatedArrayBuilder by pointer casting. |
107 TerminatedArray(); | 107 TerminatedArray(); |
108 | 108 |
109 template <typename, template <typename> class> | 109 template <typename, template <typename> class> |
110 friend class TerminatedArrayBuilder; | 110 friend class TerminatedArrayBuilder; |
111 }; | 111 }; |
112 | 112 |
113 } // namespace WTF | 113 } // namespace WTF |
114 | 114 |
115 using WTF::TerminatedArray; | 115 using WTF::TerminatedArray; |
116 | 116 |
117 #endif // TerminatedArray_h | 117 #endif // TerminatedArray_h |
OLD | NEW |