OLD | NEW |
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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 * | 18 * |
19 */ | 19 */ |
20 | 20 |
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/QuantizedAllocation.h" |
28 #include "wtf/StdLibExtras.h" | 29 #include "wtf/StdLibExtras.h" |
29 #include "wtf/UnusedParam.h" | 30 #include "wtf/UnusedParam.h" |
30 #include "wtf/VectorTraits.h" | 31 #include "wtf/VectorTraits.h" |
31 #include <limits> | |
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 4 | 41 #define WTF_VECTOR_INITIAL_SIZE 4 |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 void allocateBuffer(size_t newCapacity) | 257 void allocateBuffer(size_t newCapacity) |
258 { | 258 { |
259 ASSERT(newCapacity); | 259 ASSERT(newCapacity); |
260 // Using "unsigned" is not a limitation because Chromium's max mallo
c() is 2GB even on 64-bit. | 260 RELEASE_ASSERT(newCapacity <= QuantizedAllocation::kMaxUnquantizedAl
location / sizeof(T)); |
261 RELEASE_ASSERT(newCapacity <= std::numeric_limits<unsigned>::max() /
sizeof(T)); | 261 size_t originalSizeToAllocate = newCapacity * sizeof(T); |
262 size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T)); | 262 size_t sizeToAllocate = QuantizedAllocation::quantizedSize(originalS
izeToAllocate); |
263 m_capacity = sizeToAllocate / sizeof(T); | 263 m_capacity = sizeToAllocate / sizeof(T); |
264 m_buffer = static_cast<T*>(fastMalloc(sizeToAllocate)); | 264 m_buffer = static_cast<T*>(fastMalloc(sizeToAllocate)); |
265 } | 265 } |
266 | 266 |
267 bool shouldReallocateBuffer(size_t newCapacity) const | 267 bool shouldReallocateBuffer(size_t newCapacity) const |
268 { | 268 { |
269 return VectorTraits<T>::canMoveWithMemcpy && m_capacity && newCapaci
ty; | 269 return VectorTraits<T>::canMoveWithMemcpy && m_capacity && newCapaci
ty; |
270 } | 270 } |
271 | 271 |
272 void reallocateBuffer(size_t newCapacity) | 272 void reallocateBuffer(size_t newCapacity) |
273 { | 273 { |
274 ASSERT(shouldReallocateBuffer(newCapacity)); | 274 ASSERT(shouldReallocateBuffer(newCapacity)); |
275 // Using "unsigned" is not a limitation because Chromium's max mallo
c() is 2GB even on 64-bit. | 275 RELEASE_ASSERT(newCapacity <= QuantizedAllocation::kMaxUnquantizedAl
location / sizeof(T)); |
276 RELEASE_ASSERT(newCapacity <= std::numeric_limits<unsigned>::max() /
sizeof(T)); | 276 size_t originalSizeToAllocate = newCapacity * sizeof(T); |
277 size_t sizeToAllocate = fastMallocGoodSize(newCapacity * sizeof(T)); | 277 size_t sizeToAllocate = QuantizedAllocation::quantizedSize(originalS
izeToAllocate); |
278 m_capacity = sizeToAllocate / sizeof(T); | 278 m_capacity = sizeToAllocate / sizeof(T); |
279 m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate)); | 279 m_buffer = static_cast<T*>(fastRealloc(m_buffer, sizeToAllocate)); |
280 } | 280 } |
281 | 281 |
282 void deallocateBuffer(T* bufferToDeallocate) | 282 void deallocateBuffer(T* bufferToDeallocate) |
283 { | 283 { |
284 if (!bufferToDeallocate) | 284 if (!bufferToDeallocate) |
285 return; | 285 return; |
286 | 286 |
287 if (m_buffer == bufferToDeallocate) { | 287 if (m_buffer == bufferToDeallocate) { |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 inline bool operator!=(const Vector<T, inlineCapacity>& a, const Vector<T, i
nlineCapacity>& b) | 1064 inline bool operator!=(const Vector<T, inlineCapacity>& a, const Vector<T, i
nlineCapacity>& b) |
1065 { | 1065 { |
1066 return !(a == b); | 1066 return !(a == b); |
1067 } | 1067 } |
1068 | 1068 |
1069 } // namespace WTF | 1069 } // namespace WTF |
1070 | 1070 |
1071 using WTF::Vector; | 1071 using WTF::Vector; |
1072 | 1072 |
1073 #endif // WTF_Vector_h | 1073 #endif // WTF_Vector_h |
OLD | NEW |