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

Side by Side Diff: third_party/WebKit/Source/platform/PODArena.h

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 11 matching lines...) Expand all
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef PODArena_h 26 #ifndef PODArena_h
27 #define PODArena_h 27 #define PODArena_h
28 28
29 #include "wtf/Allocator.h" 29 #include "wtf/Allocator.h"
30 #include "wtf/Assertions.h" 30 #include "wtf/Assertions.h"
31 #include "wtf/Noncopyable.h" 31 #include "wtf/Noncopyable.h"
32 #include "wtf/PtrUtil.h" 32 #include "wtf/OwnPtr.h"
33 #include "wtf/PassOwnPtr.h"
33 #include "wtf/RefCounted.h" 34 #include "wtf/RefCounted.h"
34 #include "wtf/Vector.h" 35 #include "wtf/Vector.h"
35 #include "wtf/allocator/Partitions.h" 36 #include "wtf/allocator/Partitions.h"
36 #include <memory>
37 #include <stdint.h> 37 #include <stdint.h>
38 38
39 namespace blink { 39 namespace blink {
40 40
41 // An arena which allocates only Plain Old Data (POD), or classes and 41 // An arena which allocates only Plain Old Data (POD), or classes and
42 // structs bottoming out in Plain Old Data. NOTE: the constructors of 42 // structs bottoming out in Plain Old Data. NOTE: the constructors of
43 // the objects allocated in this arena are called, but _not_ their 43 // the objects allocated in this arena are called, but _not_ their
44 // destructors. 44 // destructors.
45 45
46 class PODArena final : public RefCounted<PODArena> { 46 class PODArena final : public RefCounted<PODArena> {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 template<class T> void* allocateBase() 125 template<class T> void* allocateBase()
126 { 126 {
127 void* ptr = 0; 127 void* ptr = 0;
128 size_t roundedSize = roundUp(sizeof(T), minAlignment<T>()); 128 size_t roundedSize = roundUp(sizeof(T), minAlignment<T>());
129 if (m_current) 129 if (m_current)
130 ptr = m_current->allocate(roundedSize); 130 ptr = m_current->allocate(roundedSize);
131 131
132 if (!ptr) { 132 if (!ptr) {
133 if (roundedSize > m_currentChunkSize) 133 if (roundedSize > m_currentChunkSize)
134 m_currentChunkSize = roundedSize; 134 m_currentChunkSize = roundedSize;
135 m_chunks.append(wrapUnique(new Chunk(m_allocator.get(), m_currentChu nkSize))); 135 m_chunks.append(adoptPtr(new Chunk(m_allocator.get(), m_currentChunk Size)));
136 m_current = m_chunks.last().get(); 136 m_current = m_chunks.last().get();
137 ptr = m_current->allocate(roundedSize); 137 ptr = m_current->allocate(roundedSize);
138 } 138 }
139 return ptr; 139 return ptr;
140 } 140 }
141 141
142 // Rounds up the given allocation size to the specified alignment. 142 // Rounds up the given allocation size to the specified alignment.
143 size_t roundUp(size_t size, size_t alignment) 143 size_t roundUp(size_t size, size_t alignment)
144 { 144 {
145 ASSERT(!(alignment % 2)); 145 ASSERT(!(alignment % 2));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 protected: 187 protected:
188 Allocator* m_allocator; 188 Allocator* m_allocator;
189 uint8_t* m_base; 189 uint8_t* m_base;
190 size_t m_size; 190 size_t m_size;
191 size_t m_currentOffset; 191 size_t m_currentOffset;
192 }; 192 };
193 193
194 RefPtr<Allocator> m_allocator; 194 RefPtr<Allocator> m_allocator;
195 Chunk* m_current; 195 Chunk* m_current;
196 size_t m_currentChunkSize; 196 size_t m_currentChunkSize;
197 Vector<std::unique_ptr<Chunk>> m_chunks; 197 Vector<OwnPtr<Chunk>> m_chunks;
198 }; 198 };
199 199
200 } // namespace blink 200 } // namespace blink
201 201
202 #endif // PODArena_h 202 #endif // PODArena_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/EventTracer.cpp ('k') | third_party/WebKit/Source/platform/PurgeableVector.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698