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 |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 { | 352 { |
353 deallocateBuffer(m_buffer); | 353 deallocateBuffer(m_buffer); |
354 m_buffer = 0; | 354 m_buffer = 0; |
355 } | 355 } |
356 | 356 |
357 void deallocateBuffer(T* bufferToDeallocate) | 357 void deallocateBuffer(T* bufferToDeallocate) |
358 { | 358 { |
359 Allocator::backingFree(bufferToDeallocate); | 359 Allocator::backingFree(bufferToDeallocate); |
360 } | 360 } |
361 | 361 |
362 bool expandBuffer(size_t newCapacity) | |
363 { | |
364 size_t sizeToAllocate = allocationSize(newCapacity); | |
365 if (Allocator::backingExpand(m_buffer, sizeToAllocate)) { | |
366 m_capacity = sizeToAllocate / sizeof(T); | |
367 return true; | |
368 } | |
369 return false; | |
370 } | |
371 | |
362 void resetBufferPointer() | 372 void resetBufferPointer() |
363 { | 373 { |
364 m_buffer = 0; | 374 m_buffer = 0; |
365 m_capacity = 0; | 375 m_capacity = 0; |
366 } | 376 } |
367 | 377 |
368 void swapVectorBuffer(VectorBuffer<T, 0, Allocator>& other) | 378 void swapVectorBuffer(VectorBuffer<T, 0, Allocator>& other) |
369 { | 379 { |
370 std::swap(m_buffer, other.m_buffer); | 380 std::swap(m_buffer, other.m_buffer); |
371 std::swap(m_capacity, other.m_capacity); | 381 std::swap(m_capacity, other.m_capacity); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 { | 431 { |
422 Allocator::backingFree(bufferToDeallocate); | 432 Allocator::backingFree(bufferToDeallocate); |
423 } | 433 } |
424 | 434 |
425 void deallocateBuffer(T* bufferToDeallocate) | 435 void deallocateBuffer(T* bufferToDeallocate) |
426 { | 436 { |
427 if (UNLIKELY(bufferToDeallocate != inlineBuffer())) | 437 if (UNLIKELY(bufferToDeallocate != inlineBuffer())) |
428 reallyDeallocateBuffer(bufferToDeallocate); | 438 reallyDeallocateBuffer(bufferToDeallocate); |
429 } | 439 } |
430 | 440 |
441 bool expandBuffer(size_t newCapacity) | |
442 { | |
443 if (newCapacity <= inlineCapacity) | |
tkent
2014/11/14 03:54:25
Is this check necessary? The callsite already has
haraken
2014/11/14 04:32:45
Removed.
| |
444 return true; | |
445 if (m_buffer == inlineBuffer()) | |
446 return false; | |
447 | |
448 size_t sizeToAllocate = allocationSize(newCapacity); | |
449 if (Allocator::backingExpand(m_buffer, sizeToAllocate)) { | |
450 m_capacity = sizeToAllocate / sizeof(T); | |
451 return true; | |
452 } | |
453 return false; | |
454 } | |
455 | |
431 void resetBufferPointer() | 456 void resetBufferPointer() |
432 { | 457 { |
433 m_buffer = inlineBuffer(); | 458 m_buffer = inlineBuffer(); |
434 m_capacity = inlineCapacity; | 459 m_capacity = inlineCapacity; |
435 } | 460 } |
436 | 461 |
437 void allocateBuffer(size_t newCapacity) | 462 void allocateBuffer(size_t newCapacity) |
438 { | 463 { |
439 // FIXME: This should ASSERT(!m_buffer) to catch misuse/leaks. | 464 // FIXME: This should ASSERT(!m_buffer) to catch misuse/leaks. |
440 if (newCapacity > inlineCapacity) | 465 if (newCapacity > inlineCapacity) |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
942 m_size = size; | 967 m_size = size; |
943 } | 968 } |
944 | 969 |
945 template<typename T, size_t inlineCapacity, typename Allocator> | 970 template<typename T, size_t inlineCapacity, typename Allocator> |
946 void Vector<T, inlineCapacity, Allocator>::reserveCapacity(size_t newCapacit y) | 971 void Vector<T, inlineCapacity, Allocator>::reserveCapacity(size_t newCapacit y) |
947 { | 972 { |
948 if (UNLIKELY(newCapacity <= capacity())) | 973 if (UNLIKELY(newCapacity <= capacity())) |
949 return; | 974 return; |
950 T* oldBuffer = begin(); | 975 T* oldBuffer = begin(); |
951 T* oldEnd = end(); | 976 T* oldEnd = end(); |
977 if (Base::expandBuffer(newCapacity)) | |
tkent
2014/11/14 03:54:25
I'm afraid this change causes performance regressi
haraken
2014/11/14 04:32:45
I observe no regression in parser benchmarks that
| |
978 return; | |
952 Base::allocateBuffer(newCapacity); | 979 Base::allocateBuffer(newCapacity); |
953 TypeOperations::move(oldBuffer, oldEnd, begin()); | 980 TypeOperations::move(oldBuffer, oldEnd, begin()); |
954 Base::deallocateBuffer(oldBuffer); | 981 Base::deallocateBuffer(oldBuffer); |
955 } | 982 } |
956 | 983 |
957 template<typename T, size_t inlineCapacity, typename Allocator> | 984 template<typename T, size_t inlineCapacity, typename Allocator> |
958 inline void Vector<T, inlineCapacity, Allocator>::reserveInitialCapacity(siz e_t initialCapacity) | 985 inline void Vector<T, inlineCapacity, Allocator>::reserveInitialCapacity(siz e_t initialCapacity) |
959 { | 986 { |
960 ASSERT(!m_size); | 987 ASSERT(!m_size); |
961 ASSERT(capacity() == inlineCapacity); | 988 ASSERT(capacity() == inlineCapacity); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1191 struct NeedsTracing<Vector<T, N> > { | 1218 struct NeedsTracing<Vector<T, N> > { |
1192 static const bool value = false; | 1219 static const bool value = false; |
1193 }; | 1220 }; |
1194 #endif | 1221 #endif |
1195 | 1222 |
1196 } // namespace WTF | 1223 } // namespace WTF |
1197 | 1224 |
1198 using WTF::Vector; | 1225 using WTF::Vector; |
1199 | 1226 |
1200 #endif // WTF_Vector_h | 1227 #endif // WTF_Vector_h |
OLD | NEW |