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

Side by Side Diff: third_party/WebKit/Source/wtf/TerminatedArray.h

Issue 2021713002: (Heap)TerminatedArrayBuilders are stack allocated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tidy HeapTerminatedArray Created 4 years, 6 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 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/OwnPtr.h" 8 #include "wtf/OwnPtr.h"
9 #include "wtf/allocator/Partitions.h" 9 #include "wtf/allocator/Partitions.h"
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } 67 }
68 68
69 // Match Allocator semantics to be able to use OwnPtr<TerminatedArray>. 69 // Match Allocator semantics to be able to use OwnPtr<TerminatedArray>.
70 void operator delete(void* p) { ::WTF::Partitions::fastFree(p); } 70 void operator delete(void* p) { ::WTF::Partitions::fastFree(p); }
71 71
72 private: 72 private:
73 // Allocator describes how TerminatedArrayBuilder should create new instance s 73 // Allocator describes how TerminatedArrayBuilder should create new instance s
74 // of TerminateArray and manage their lifetimes. 74 // of TerminateArray and manage their lifetimes.
75 struct Allocator { 75 struct Allocator {
76 STATIC_ONLY(Allocator); 76 STATIC_ONLY(Allocator);
77 typedef PassOwnPtr<TerminatedArray> PassPtr; 77 using PassPtr = PassOwnPtr<TerminatedArray>;
78 typedef OwnPtr<TerminatedArray> Ptr; 78 using Ptr = OwnPtr<TerminatedArray>;
79 79
80 static PassPtr release(Ptr& ptr) 80 static PassPtr release(Ptr& ptr)
81 { 81 {
82 return ptr.release(); 82 return ptr.release();
83 } 83 }
84 84
85 static PassPtr create(size_t capacity) 85 static PassPtr create(size_t capacity)
86 { 86 {
87 return adoptPtr(static_cast<TerminatedArray*>(WTF::Partitions::fastM alloc(capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); 87 return adoptPtr(static_cast<TerminatedArray*>(WTF::Partitions::fastM alloc(capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T))));
88 } 88 }
89 89
90 static PassPtr resize(Ptr ptr, size_t capacity) 90 static PassPtr resize(Ptr ptr, size_t capacity)
91 { 91 {
92 return adoptPtr(static_cast<TerminatedArray*>(WTF::Partitions::fastR ealloc(ptr.leakPtr(), capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T)))); 92 return adoptPtr(static_cast<TerminatedArray*>(WTF::Partitions::fastR ealloc(ptr.leakPtr(), capacity * sizeof(T), WTF_HEAP_PROFILER_TYPE_NAME(T))));
93 } 93 }
94 }; 94 };
95 95
96 // Prohibit construction. Allocator makes TerminatedArray instances for 96 // Prohibit construction. Allocator makes TerminatedArray instances for
97 // TerminatedArrayBuilder by pointer casting. 97 // TerminatedArrayBuilder by pointer casting.
98 TerminatedArray(); 98 TerminatedArray();
99 99
100 template<typename, template <typename> class> friend class TerminatedArrayBu ilder; 100 template<typename, template <typename> class> friend class TerminatedArrayBu ilder;
101 }; 101 };
102 102
103 } // namespace WTF 103 } // namespace WTF
104 104
105 using WTF::TerminatedArray; 105 using WTF::TerminatedArray;
106 106
107 #endif // TerminatedArray_h 107 #endif // TerminatedArray_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698