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

Side by Side Diff: Source/wtf/Vector.h

Issue 23604048: Get rid of fastMallocGoodSize() and replace it with something generic. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix compile error. Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 10 matching lines...) Expand all
21 #ifndef WTF_Vector_h 21 #ifndef WTF_Vector_h
22 #define WTF_Vector_h 22 #define WTF_Vector_h
23 23
24 #include "wtf/Alignment.h" 24 #include "wtf/Alignment.h"
25 #include "wtf/FastAllocBase.h" 25 #include "wtf/FastAllocBase.h"
26 #include "wtf/Noncopyable.h" 26 #include "wtf/Noncopyable.h"
27 #include "wtf/NotFound.h" 27 #include "wtf/NotFound.h"
28 #include "wtf/StdLibExtras.h" 28 #include "wtf/StdLibExtras.h"
29 #include "wtf/UnusedParam.h" 29 #include "wtf/UnusedParam.h"
30 #include "wtf/VectorTraits.h" 30 #include "wtf/VectorTraits.h"
31 #include <limits> 31 #include "wtf/WTF.h"
32 #include <utility> 32 #include <utility>
33 #include <string.h> 33 #include <string.h>
34 34
35 namespace WTF { 35 namespace WTF {
36 36
37 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 37 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
38 static const size_t kInitialVectorSize = 1; 38 static const size_t kInitialVectorSize = 1;
39 #else 39 #else
40 #ifndef WTF_VECTOR_INITIAL_SIZE 40 #ifndef WTF_VECTOR_INITIAL_SIZE
41 #define WTF_VECTOR_INITIAL_SIZE 16 41 #define WTF_VECTOR_INITIAL_SIZE 16
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 static bool compare(const T* a, const T* b, size_t size) 247 static bool compare(const T* a, const T* b, size_t size)
248 { 248 {
249 return VectorComparer<VectorTraits<T>::canCompareWithMemcmp, T>::com pare(a, b, size); 249 return VectorComparer<VectorTraits<T>::canCompareWithMemcmp, T>::com pare(a, b, size);
250 } 250 }
251 }; 251 };
252 252
253 template<typename T> 253 template<typename T>
254 class VectorBufferBase { 254 class VectorBufferBase {
255 WTF_MAKE_NONCOPYABLE(VectorBufferBase); 255 WTF_MAKE_NONCOPYABLE(VectorBufferBase);
256 public: 256 public:
257 size_t roundSize(size_t size)
258 {
259 return (size + 7) & ~7;
260 }
261
257 void allocateBuffer(size_t newCapacity) 262 void allocateBuffer(size_t newCapacity)
258 { 263 {
259 ASSERT(newCapacity); 264 ASSERT(newCapacity);
260 // Using "unsigned" is not a limitation because Chromium's max mallo c() is 2GB even on 64-bit. 265 RELEASE_ASSERT(newCapacity <= WTF::QuantizedAllocation::kMaxUnquanti zedAllocation / sizeof(T));
abarth-chromium 2013/09/07 05:08:24 WTF:: <-- no need for WTF prefix inside WTF.
261 RELEASE_ASSERT(newCapacity <= std::numeric_limits<unsigned>::max() / sizeof(T)); 266 size_t origSizeToAllocate = newCapacity * sizeof(T);
abarth-chromium 2013/09/07 05:08:24 origSizeToAllocate ---> originalSizeToAllocate Pl
262 size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T)); 267 size_t sizeToAllocate = WTF::QuantizedAllocation::quantizedSize(orig SizeToAllocate);
263 m_capacity = sizeToAllocate / sizeof(T); 268 m_capacity = sizeToAllocate / sizeof(T);
264 m_buffer = static_cast<T*>(fastMalloc(sizeToAllocate)); 269 m_buffer = static_cast<T*>(fastMalloc(sizeToAllocate));
265 } 270 }
266 271
267 bool shouldReallocateBuffer(size_t newCapacity) const 272 bool shouldReallocateBuffer(size_t newCapacity) const
268 { 273 {
269 return VectorTraits<T>::canMoveWithMemcpy && m_capacity && newCapaci ty; 274 return VectorTraits<T>::canMoveWithMemcpy && m_capacity && newCapaci ty;
270 } 275 }
271 276
272 void reallocateBuffer(size_t newCapacity) 277 void reallocateBuffer(size_t newCapacity)
273 { 278 {
274 ASSERT(shouldReallocateBuffer(newCapacity)); 279 ASSERT(shouldReallocateBuffer(newCapacity));
275 // Using "unsigned" is not a limitation because Chromium's max mallo c() is 2GB even on 64-bit. 280 RELEASE_ASSERT(newCapacity <= WTF::QuantizedAllocation::kMaxUnquanti zedAllocation / sizeof(T));
276 RELEASE_ASSERT(newCapacity <= std::numeric_limits<unsigned>::max() / sizeof(T)); 281 size_t origSizeToAllocate = newCapacity * sizeof(T);
277 size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T)); 282 size_t sizeToAllocate = WTF::QuantizedAllocation::quantizedSize(orig SizeToAllocate);
278 m_capacity = sizeToAllocate / sizeof(T); 283 m_capacity = sizeToAllocate / sizeof(T);
279 m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate)); 284 m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate));
280 } 285 }
281 286
282 void deallocateBuffer(T* bufferToDeallocate) 287 void deallocateBuffer(T* bufferToDeallocate)
283 { 288 {
284 if (!bufferToDeallocate) 289 if (!bufferToDeallocate)
285 return; 290 return;
286 291
287 if (m_buffer == bufferToDeallocate) { 292 if (m_buffer == bufferToDeallocate) {
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 inline bool operator!=(const Vector<T, inlineCapacity>& a, const Vector<T, i nlineCapacity>& b) 1069 inline bool operator!=(const Vector<T, inlineCapacity>& a, const Vector<T, i nlineCapacity>& b)
1065 { 1070 {
1066 return !(a == b); 1071 return !(a == b);
1067 } 1072 }
1068 1073
1069 } // namespace WTF 1074 } // namespace WTF
1070 1075
1071 using WTF::Vector; 1076 using WTF::Vector;
1072 1077
1073 #endif // WTF_Vector_h 1078 #endif // WTF_Vector_h
OLDNEW
« no previous file with comments | « Source/wtf/FastMalloc.cpp ('k') | Source/wtf/WTF.h » ('j') | Source/wtf/WTF.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698