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

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

Issue 1865063003: CL for perf tryjob on android Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/Source/wtf/TypedArrayBase.h ('k') | third_party/WebKit/Source/wtf/WTF.cpp » ('j') | 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 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 830
831 Vector(Vector&&); 831 Vector(Vector&&);
832 Vector& operator=(Vector&&); 832 Vector& operator=(Vector&&);
833 833
834 size_t size() const { return m_size; } 834 size_t size() const { return m_size; }
835 size_t capacity() const { return Base::capacity(); } 835 size_t capacity() const { return Base::capacity(); }
836 bool isEmpty() const { return !size(); } 836 bool isEmpty() const { return !size(); }
837 837
838 T& at(size_t i) 838 T& at(size_t i)
839 { 839 {
840 RELEASE_ASSERT(i < size()); 840 CHECK_LT(i, size());
841 return Base::buffer()[i]; 841 return Base::buffer()[i];
842 } 842 }
843 const T& at(size_t i) const 843 const T& at(size_t i) const
844 { 844 {
845 RELEASE_ASSERT(i < size()); 845 CHECK_LT(i, size());
846 return Base::buffer()[i]; 846 return Base::buffer()[i];
847 } 847 }
848 848
849 T& operator[](size_t i) { return at(i); } 849 T& operator[](size_t i) { return at(i); }
850 const T& operator[](size_t i) const { return at(i); } 850 const T& operator[](size_t i) const { return at(i); }
851 851
852 T* data() { return Base::buffer(); } 852 T* data() { return Base::buffer(); }
853 const T* data() const { return Base::buffer(); } 853 const T* data() const { return Base::buffer(); }
854 854
855 iterator begin() { return data(); } 855 iterator begin() { return data(); }
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 size_t oldCapacity = capacity(); 1114 size_t oldCapacity = capacity();
1115 size_t expandedCapacity = oldCapacity; 1115 size_t expandedCapacity = oldCapacity;
1116 // We use a more aggressive expansion strategy for Vectors with inline 1116 // We use a more aggressive expansion strategy for Vectors with inline
1117 // storage. This is because they are more likely to be on the stack, so the 1117 // storage. This is because they are more likely to be on the stack, so the
1118 // risk of heap bloat is minimized. Furthermore, exceeding the inline 1118 // risk of heap bloat is minimized. Furthermore, exceeding the inline
1119 // capacity limit is not supposed to happen in the common case and may 1119 // capacity limit is not supposed to happen in the common case and may
1120 // indicate a pathological condition or microbenchmark. 1120 // indicate a pathological condition or microbenchmark.
1121 if (INLINE_CAPACITY) { 1121 if (INLINE_CAPACITY) {
1122 expandedCapacity *= 2; 1122 expandedCapacity *= 2;
1123 // Check for integer overflow, which could happen in the 32-bit build. 1123 // Check for integer overflow, which could happen in the 32-bit build.
1124 RELEASE_ASSERT(expandedCapacity > oldCapacity); 1124 CHECK_GT(expandedCapacity, oldCapacity);
1125 } else { 1125 } else {
1126 // This cannot integer overflow. 1126 // This cannot integer overflow.
1127 // On 64-bit, the "expanded" integer is 32-bit, and any encroachment 1127 // On 64-bit, the "expanded" integer is 32-bit, and any encroachment
1128 // above 2^32 will fail allocation in allocateBuffer(). On 32-bit, 1128 // above 2^32 will fail allocation in allocateBuffer(). On 32-bit,
1129 // there's not enough address space to hold the old and new buffers. In 1129 // there's not enough address space to hold the old and new buffers. In
1130 // addition, our underlying allocator is supposed to always fail on > 1130 // addition, our underlying allocator is supposed to always fail on >
1131 // (2^31 - 1) allocations. 1131 // (2^31 - 1) allocations.
1132 expandedCapacity += (expandedCapacity / 4) + 1; 1132 expandedCapacity += (expandedCapacity / 4) + 1;
1133 } 1133 }
1134 reserveCapacity(std::max(newMinCapacity, std::max(static_cast<size_t>(kIniti alVectorSize), expandedCapacity))); 1134 reserveCapacity(std::max(newMinCapacity, std::max(static_cast<size_t>(kIniti alVectorSize), expandedCapacity)));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 template <typename T, size_t inlineCapacity, typename Allocator> 1280 template <typename T, size_t inlineCapacity, typename Allocator>
1281 template <typename U> 1281 template <typename U>
1282 void Vector<T, inlineCapacity, Allocator>::append(const U* data, size_t dataSize ) 1282 void Vector<T, inlineCapacity, Allocator>::append(const U* data, size_t dataSize )
1283 { 1283 {
1284 ASSERT(Allocator::isAllocationAllowed()); 1284 ASSERT(Allocator::isAllocationAllowed());
1285 size_t newSize = m_size + dataSize; 1285 size_t newSize = m_size + dataSize;
1286 if (newSize > capacity()) { 1286 if (newSize > capacity()) {
1287 data = expandCapacity(newSize, data); 1287 data = expandCapacity(newSize, data);
1288 ASSERT(begin()); 1288 ASSERT(begin());
1289 } 1289 }
1290 RELEASE_ASSERT(newSize >= m_size); 1290 CHECK_GE(newSize, m_size);
1291 T* dest = end(); 1291 T* dest = end();
1292 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, newSize); 1292 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, newSize);
1293 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], dest); 1293 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], dest);
1294 m_size = newSize; 1294 m_size = newSize;
1295 } 1295 }
1296 1296
1297 template <typename T, size_t inlineCapacity, typename Allocator> 1297 template <typename T, size_t inlineCapacity, typename Allocator>
1298 template <typename U> 1298 template <typename U>
1299 ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::append(U&& val) 1299 ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::append(U&& val)
1300 { 1300 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 inline void Vector<T, inlineCapacity, Allocator>::appendVector(const Vector<U, o therCapacity, OtherAllocator>& val) 1347 inline void Vector<T, inlineCapacity, Allocator>::appendVector(const Vector<U, o therCapacity, OtherAllocator>& val)
1348 { 1348 {
1349 append(val.begin(), val.size()); 1349 append(val.begin(), val.size());
1350 } 1350 }
1351 1351
1352 template <typename T, size_t inlineCapacity, typename Allocator> 1352 template <typename T, size_t inlineCapacity, typename Allocator>
1353 template <typename U> 1353 template <typename U>
1354 void Vector<T, inlineCapacity, Allocator>::insert(size_t position, const U* data , size_t dataSize) 1354 void Vector<T, inlineCapacity, Allocator>::insert(size_t position, const U* data , size_t dataSize)
1355 { 1355 {
1356 ASSERT(Allocator::isAllocationAllowed()); 1356 ASSERT(Allocator::isAllocationAllowed());
1357 RELEASE_ASSERT(position <= size()); 1357 CHECK_LE(position, size());
1358 size_t newSize = m_size + dataSize; 1358 size_t newSize = m_size + dataSize;
1359 if (newSize > capacity()) { 1359 if (newSize > capacity()) {
1360 data = expandCapacity(newSize, data); 1360 data = expandCapacity(newSize, data);
1361 ASSERT(begin()); 1361 ASSERT(begin());
1362 } 1362 }
1363 RELEASE_ASSERT(newSize >= m_size); 1363 CHECK_GE(newSize, m_size);
1364 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, newSize); 1364 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, newSize);
1365 T* spot = begin() + position; 1365 T* spot = begin() + position;
1366 TypeOperations::moveOverlapping(spot, end(), spot + dataSize); 1366 TypeOperations::moveOverlapping(spot, end(), spot + dataSize);
1367 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], spot); 1367 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], spot);
1368 m_size = newSize; 1368 m_size = newSize;
1369 } 1369 }
1370 1370
1371 template <typename T, size_t inlineCapacity, typename Allocator> 1371 template <typename T, size_t inlineCapacity, typename Allocator>
1372 template <typename U> 1372 template <typename U>
1373 inline void Vector<T, inlineCapacity, Allocator>::insert(size_t position, U&& va l) 1373 inline void Vector<T, inlineCapacity, Allocator>::insert(size_t position, U&& va l)
1374 { 1374 {
1375 ASSERT(Allocator::isAllocationAllowed()); 1375 ASSERT(Allocator::isAllocationAllowed());
1376 RELEASE_ASSERT(position <= size()); 1376 CHECK_LE(position, size());
1377 typename std::remove_reference<U>::type* data = &val; 1377 typename std::remove_reference<U>::type* data = &val;
1378 if (size() == capacity()) { 1378 if (size() == capacity()) {
1379 data = expandCapacity(size() + 1, data); 1379 data = expandCapacity(size() + 1, data);
1380 ASSERT(begin()); 1380 ASSERT(begin());
1381 } 1381 }
1382 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size + 1); 1382 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size + 1);
1383 T* spot = begin() + position; 1383 T* spot = begin() + position;
1384 TypeOperations::moveOverlapping(spot, end(), spot + 1); 1384 TypeOperations::moveOverlapping(spot, end(), spot + 1);
1385 new (NotNull, spot) T(std::forward<U>(*data)); 1385 new (NotNull, spot) T(std::forward<U>(*data));
1386 ++m_size; 1386 ++m_size;
(...skipping 23 matching lines...) Expand all
1410 template <typename T, size_t inlineCapacity, typename Allocator> 1410 template <typename T, size_t inlineCapacity, typename Allocator>
1411 template <typename U, size_t c, typename V> 1411 template <typename U, size_t c, typename V>
1412 inline void Vector<T, inlineCapacity, Allocator>::prependVector(const Vector<U, c, V>& val) 1412 inline void Vector<T, inlineCapacity, Allocator>::prependVector(const Vector<U, c, V>& val)
1413 { 1413 {
1414 insert(0, val.begin(), val.size()); 1414 insert(0, val.begin(), val.size());
1415 } 1415 }
1416 1416
1417 template <typename T, size_t inlineCapacity, typename Allocator> 1417 template <typename T, size_t inlineCapacity, typename Allocator>
1418 inline void Vector<T, inlineCapacity, Allocator>::remove(size_t position) 1418 inline void Vector<T, inlineCapacity, Allocator>::remove(size_t position)
1419 { 1419 {
1420 RELEASE_ASSERT(position < size()); 1420 CHECK_LT(position, size());
1421 T* spot = begin() + position; 1421 T* spot = begin() + position;
1422 spot->~T(); 1422 spot->~T();
1423 TypeOperations::moveOverlapping(spot + 1, end(), spot); 1423 TypeOperations::moveOverlapping(spot + 1, end(), spot);
1424 clearUnusedSlots(end() - 1, end()); 1424 clearUnusedSlots(end() - 1, end());
1425 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size - 1); 1425 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size - 1);
1426 --m_size; 1426 --m_size;
1427 } 1427 }
1428 1428
1429 template <typename T, size_t inlineCapacity, typename Allocator> 1429 template <typename T, size_t inlineCapacity, typename Allocator>
1430 inline void Vector<T, inlineCapacity, Allocator>::remove(size_t position, size_t length) 1430 inline void Vector<T, inlineCapacity, Allocator>::remove(size_t position, size_t length)
1431 { 1431 {
1432 ASSERT_WITH_SECURITY_IMPLICATION(position <= size()); 1432 ASSERT_WITH_SECURITY_IMPLICATION(position <= size());
1433 if (!length) 1433 if (!length)
1434 return; 1434 return;
1435 RELEASE_ASSERT(position + length <= size()); 1435 CHECK_LE(position + length, size());
1436 T* beginSpot = begin() + position; 1436 T* beginSpot = begin() + position;
1437 T* endSpot = beginSpot + length; 1437 T* endSpot = beginSpot + length;
1438 TypeOperations::destruct(beginSpot, endSpot); 1438 TypeOperations::destruct(beginSpot, endSpot);
1439 TypeOperations::moveOverlapping(endSpot, end(), beginSpot); 1439 TypeOperations::moveOverlapping(endSpot, end(), beginSpot);
1440 clearUnusedSlots(end() - length, end()); 1440 clearUnusedSlots(end() - length, end());
1441 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size - length); 1441 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size - length);
1442 m_size -= length; 1442 m_size -= length;
1443 } 1443 }
1444 1444
1445 template <typename T, size_t inlineCapacity, typename Allocator> 1445 template <typename T, size_t inlineCapacity, typename Allocator>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis itor, *const_cast<T*>(bufferEntry)); 1496 Allocator::template trace<VisitorDispatcher, T, VectorTraits<T>>(vis itor, *const_cast<T*>(bufferEntry));
1497 checkUnusedSlots(buffer() + size(), buffer() + capacity()); 1497 checkUnusedSlots(buffer() + size(), buffer() + capacity());
1498 } 1498 }
1499 } 1499 }
1500 1500
1501 } // namespace WTF 1501 } // namespace WTF
1502 1502
1503 using WTF::Vector; 1503 using WTF::Vector;
1504 1504
1505 #endif // WTF_Vector_h 1505 #endif // WTF_Vector_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/TypedArrayBase.h ('k') | third_party/WebKit/Source/wtf/WTF.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698