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

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

Issue 44293004: Devirtualize PODArena and PODArena::Chunk's destructors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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 | « no previous file | 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 /* 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return new (allocateBase<T>()) T(argument1); 95 return new (allocateBase<T>()) T(argument1);
96 } 96 }
97 97
98 // The initial size of allocated chunks; increases as necessary to 98 // The initial size of allocated chunks; increases as necessary to
99 // satisfy large allocations. Mainly public for unit tests. 99 // satisfy large allocations. Mainly public for unit tests.
100 enum { 100 enum {
101 DefaultChunkSize = 16384 101 DefaultChunkSize = 16384
102 }; 102 };
103 103
104 protected: 104 protected:
105 virtual ~PODArena() { }
106 friend class WTF::RefCounted<PODArena>; 105 friend class WTF::RefCounted<PODArena>;
107 106
108 PODArena() 107 PODArena()
109 : m_allocator(FastMallocAllocator::create()) 108 : m_allocator(FastMallocAllocator::create())
110 , m_current(0) 109 , m_current(0)
111 , m_currentChunkSize(DefaultChunkSize) { } 110 , m_currentChunkSize(DefaultChunkSize) { }
112 111
113 explicit PODArena(PassRefPtr<Allocator> allocator) 112 explicit PODArena(PassRefPtr<Allocator> allocator)
114 : m_allocator(allocator) 113 : m_allocator(allocator)
115 , m_current(0) 114 , m_current(0)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 Chunk(Allocator* allocator, size_t size) 154 Chunk(Allocator* allocator, size_t size)
156 : m_allocator(allocator) 155 : m_allocator(allocator)
157 , m_size(size) 156 , m_size(size)
158 , m_currentOffset(0) 157 , m_currentOffset(0)
159 { 158 {
160 m_base = static_cast<uint8_t*>(m_allocator->allocate(size)); 159 m_base = static_cast<uint8_t*>(m_allocator->allocate(size));
161 } 160 }
162 161
163 // Frees the memory allocated from the Allocator in the 162 // Frees the memory allocated from the Allocator in the
164 // constructor. 163 // constructor.
165 virtual ~Chunk() 164 ~Chunk()
166 { 165 {
167 m_allocator->free(m_base); 166 m_allocator->free(m_base);
168 } 167 }
169 168
170 // Returns a pointer to "size" bytes of storage, or 0 if this 169 // Returns a pointer to "size" bytes of storage, or 0 if this
171 // Chunk could not satisfy the allocation. 170 // Chunk could not satisfy the allocation.
172 void* allocate(size_t size) 171 void* allocate(size_t size)
173 { 172 {
174 // Check for overflow 173 // Check for overflow
175 if (m_currentOffset + size < m_currentOffset) 174 if (m_currentOffset + size < m_currentOffset)
(...skipping 16 matching lines...) Expand all
192 191
193 RefPtr<Allocator> m_allocator; 192 RefPtr<Allocator> m_allocator;
194 Chunk* m_current; 193 Chunk* m_current;
195 size_t m_currentChunkSize; 194 size_t m_currentChunkSize;
196 Vector<OwnPtr<Chunk> > m_chunks; 195 Vector<OwnPtr<Chunk> > m_chunks;
197 }; 196 };
198 197
199 } // namespace WebCore 198 } // namespace WebCore
200 199
201 #endif // PODArena_h 200 #endif // PODArena_h
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698