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

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

Issue 720163002: Oilpan: Vector::reserveCapacity shouldn't reallocate backing storage always (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/wtf/Deque.h ('k') | 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) 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
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
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 ASSERT(newCapacity > inlineCapacity);
444 if (m_buffer == inlineBuffer())
445 return false;
446
447 size_t sizeToAllocate = allocationSize(newCapacity);
448 if (Allocator::backingExpand(m_buffer, sizeToAllocate)) {
449 m_capacity = sizeToAllocate / sizeof(T);
450 return true;
451 }
452 return false;
453 }
454
431 void resetBufferPointer() 455 void resetBufferPointer()
432 { 456 {
433 m_buffer = inlineBuffer(); 457 m_buffer = inlineBuffer();
434 m_capacity = inlineCapacity; 458 m_capacity = inlineCapacity;
435 } 459 }
436 460
437 void allocateBuffer(size_t newCapacity) 461 void allocateBuffer(size_t newCapacity)
438 { 462 {
439 // FIXME: This should ASSERT(!m_buffer) to catch misuse/leaks. 463 // FIXME: This should ASSERT(!m_buffer) to catch misuse/leaks.
440 if (newCapacity > inlineCapacity) 464 if (newCapacity > inlineCapacity)
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 m_size = size; 966 m_size = size;
943 } 967 }
944 968
945 template<typename T, size_t inlineCapacity, typename Allocator> 969 template<typename T, size_t inlineCapacity, typename Allocator>
946 void Vector<T, inlineCapacity, Allocator>::reserveCapacity(size_t newCapacit y) 970 void Vector<T, inlineCapacity, Allocator>::reserveCapacity(size_t newCapacit y)
947 { 971 {
948 if (UNLIKELY(newCapacity <= capacity())) 972 if (UNLIKELY(newCapacity <= capacity()))
949 return; 973 return;
950 T* oldBuffer = begin(); 974 T* oldBuffer = begin();
951 T* oldEnd = end(); 975 T* oldEnd = end();
976 if (Base::expandBuffer(newCapacity))
977 return;
952 Base::allocateBuffer(newCapacity); 978 Base::allocateBuffer(newCapacity);
953 TypeOperations::move(oldBuffer, oldEnd, begin()); 979 TypeOperations::move(oldBuffer, oldEnd, begin());
954 Base::deallocateBuffer(oldBuffer); 980 Base::deallocateBuffer(oldBuffer);
955 } 981 }
956 982
957 template<typename T, size_t inlineCapacity, typename Allocator> 983 template<typename T, size_t inlineCapacity, typename Allocator>
958 inline void Vector<T, inlineCapacity, Allocator>::reserveInitialCapacity(siz e_t initialCapacity) 984 inline void Vector<T, inlineCapacity, Allocator>::reserveInitialCapacity(siz e_t initialCapacity)
959 { 985 {
960 ASSERT(!m_size); 986 ASSERT(!m_size);
961 ASSERT(capacity() == inlineCapacity); 987 ASSERT(capacity() == inlineCapacity);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 struct NeedsTracing<Vector<T, N> > { 1217 struct NeedsTracing<Vector<T, N> > {
1192 static const bool value = false; 1218 static const bool value = false;
1193 }; 1219 };
1194 #endif 1220 #endif
1195 1221
1196 } // namespace WTF 1222 } // namespace WTF
1197 1223
1198 using WTF::Vector; 1224 using WTF::Vector;
1199 1225
1200 #endif // WTF_Vector_h 1226 #endif // WTF_Vector_h
OLDNEW
« no previous file with comments | « Source/wtf/Deque.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698