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

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

Issue 1859513002: Revert of Replace all occurrences of RELEASE_ASSERT in wtf with CHECK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [rebase: remove BitArray.h diff] 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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 834
835 Vector(Vector&&); 835 Vector(Vector&&);
836 Vector& operator=(Vector&&); 836 Vector& operator=(Vector&&);
837 837
838 size_t size() const { return m_size; } 838 size_t size() const { return m_size; }
839 size_t capacity() const { return Base::capacity(); } 839 size_t capacity() const { return Base::capacity(); }
840 bool isEmpty() const { return !size(); } 840 bool isEmpty() const { return !size(); }
841 841
842 T& at(size_t i) 842 T& at(size_t i)
843 { 843 {
844 CHECK_LT(i, size()); 844 RELEASE_ASSERT(i < size());
845 return Base::buffer()[i]; 845 return Base::buffer()[i];
846 } 846 }
847 const T& at(size_t i) const 847 const T& at(size_t i) const
848 { 848 {
849 CHECK_LT(i, size()); 849 RELEASE_ASSERT(i < size());
850 return Base::buffer()[i]; 850 return Base::buffer()[i];
851 } 851 }
852 852
853 T& operator[](size_t i) { return at(i); } 853 T& operator[](size_t i) { return at(i); }
854 const T& operator[](size_t i) const { return at(i); } 854 const T& operator[](size_t i) const { return at(i); }
855 855
856 T* data() { return Base::buffer(); } 856 T* data() { return Base::buffer(); }
857 const T* data() const { return Base::buffer(); } 857 const T* data() const { return Base::buffer(); }
858 858
859 iterator begin() { return data(); } 859 iterator begin() { return data(); }
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 size_t oldCapacity = capacity(); 1118 size_t oldCapacity = capacity();
1119 size_t expandedCapacity = oldCapacity; 1119 size_t expandedCapacity = oldCapacity;
1120 // We use a more aggressive expansion strategy for Vectors with inline 1120 // We use a more aggressive expansion strategy for Vectors with inline
1121 // storage. This is because they are more likely to be on the stack, so the 1121 // storage. This is because they are more likely to be on the stack, so the
1122 // risk of heap bloat is minimized. Furthermore, exceeding the inline 1122 // risk of heap bloat is minimized. Furthermore, exceeding the inline
1123 // capacity limit is not supposed to happen in the common case and may 1123 // capacity limit is not supposed to happen in the common case and may
1124 // indicate a pathological condition or microbenchmark. 1124 // indicate a pathological condition or microbenchmark.
1125 if (INLINE_CAPACITY) { 1125 if (INLINE_CAPACITY) {
1126 expandedCapacity *= 2; 1126 expandedCapacity *= 2;
1127 // Check for integer overflow, which could happen in the 32-bit build. 1127 // Check for integer overflow, which could happen in the 32-bit build.
1128 CHECK_GT(expandedCapacity, oldCapacity); 1128 RELEASE_ASSERT(expandedCapacity > oldCapacity);
1129 } else { 1129 } else {
1130 // This cannot integer overflow. 1130 // This cannot integer overflow.
1131 // On 64-bit, the "expanded" integer is 32-bit, and any encroachment 1131 // On 64-bit, the "expanded" integer is 32-bit, and any encroachment
1132 // above 2^32 will fail allocation in allocateBuffer(). On 32-bit, 1132 // above 2^32 will fail allocation in allocateBuffer(). On 32-bit,
1133 // there's not enough address space to hold the old and new buffers. In 1133 // there's not enough address space to hold the old and new buffers. In
1134 // addition, our underlying allocator is supposed to always fail on > 1134 // addition, our underlying allocator is supposed to always fail on >
1135 // (2^31 - 1) allocations. 1135 // (2^31 - 1) allocations.
1136 expandedCapacity += (expandedCapacity / 4) + 1; 1136 expandedCapacity += (expandedCapacity / 4) + 1;
1137 } 1137 }
1138 reserveCapacity(std::max(newMinCapacity, std::max(static_cast<size_t>(kIniti alVectorSize), expandedCapacity))); 1138 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
1284 template <typename T, size_t inlineCapacity, typename Allocator> 1284 template <typename T, size_t inlineCapacity, typename Allocator>
1285 template <typename U> 1285 template <typename U>
1286 void Vector<T, inlineCapacity, Allocator>::append(const U* data, size_t dataSize ) 1286 void Vector<T, inlineCapacity, Allocator>::append(const U* data, size_t dataSize )
1287 { 1287 {
1288 ASSERT(Allocator::isAllocationAllowed()); 1288 ASSERT(Allocator::isAllocationAllowed());
1289 size_t newSize = m_size + dataSize; 1289 size_t newSize = m_size + dataSize;
1290 if (newSize > capacity()) { 1290 if (newSize > capacity()) {
1291 data = expandCapacity(newSize, data); 1291 data = expandCapacity(newSize, data);
1292 ASSERT(begin()); 1292 ASSERT(begin());
1293 } 1293 }
1294 CHECK_GE(newSize, m_size); 1294 RELEASE_ASSERT(newSize >= m_size);
1295 T* dest = end(); 1295 T* dest = end();
1296 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, newSize); 1296 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, newSize);
1297 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], dest); 1297 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], dest);
1298 m_size = newSize; 1298 m_size = newSize;
1299 } 1299 }
1300 1300
1301 template <typename T, size_t inlineCapacity, typename Allocator> 1301 template <typename T, size_t inlineCapacity, typename Allocator>
1302 template <typename U> 1302 template <typename U>
1303 ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::append(U&& val) 1303 ALWAYS_INLINE void Vector<T, inlineCapacity, Allocator>::append(U&& val)
1304 { 1304 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 inline void Vector<T, inlineCapacity, Allocator>::appendVector(const Vector<U, o therCapacity, OtherAllocator>& val) 1351 inline void Vector<T, inlineCapacity, Allocator>::appendVector(const Vector<U, o therCapacity, OtherAllocator>& val)
1352 { 1352 {
1353 append(val.begin(), val.size()); 1353 append(val.begin(), val.size());
1354 } 1354 }
1355 1355
1356 template <typename T, size_t inlineCapacity, typename Allocator> 1356 template <typename T, size_t inlineCapacity, typename Allocator>
1357 template <typename U> 1357 template <typename U>
1358 void Vector<T, inlineCapacity, Allocator>::insert(size_t position, const U* data , size_t dataSize) 1358 void Vector<T, inlineCapacity, Allocator>::insert(size_t position, const U* data , size_t dataSize)
1359 { 1359 {
1360 ASSERT(Allocator::isAllocationAllowed()); 1360 ASSERT(Allocator::isAllocationAllowed());
1361 CHECK_LE(position, size()); 1361 RELEASE_ASSERT(position <= size());
1362 size_t newSize = m_size + dataSize; 1362 size_t newSize = m_size + dataSize;
1363 if (newSize > capacity()) { 1363 if (newSize > capacity()) {
1364 data = expandCapacity(newSize, data); 1364 data = expandCapacity(newSize, data);
1365 ASSERT(begin()); 1365 ASSERT(begin());
1366 } 1366 }
1367 CHECK_GE(newSize, m_size); 1367 RELEASE_ASSERT(newSize >= m_size);
1368 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, newSize); 1368 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, newSize);
1369 T* spot = begin() + position; 1369 T* spot = begin() + position;
1370 TypeOperations::moveOverlapping(spot, end(), spot + dataSize); 1370 TypeOperations::moveOverlapping(spot, end(), spot + dataSize);
1371 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], spot); 1371 VectorCopier<VectorTraits<T>::canCopyWithMemcpy, T>::uninitializedCopy(data, &data[dataSize], spot);
1372 m_size = newSize; 1372 m_size = newSize;
1373 } 1373 }
1374 1374
1375 template <typename T, size_t inlineCapacity, typename Allocator> 1375 template <typename T, size_t inlineCapacity, typename Allocator>
1376 template <typename U> 1376 template <typename U>
1377 inline void Vector<T, inlineCapacity, Allocator>::insert(size_t position, U&& va l) 1377 inline void Vector<T, inlineCapacity, Allocator>::insert(size_t position, U&& va l)
1378 { 1378 {
1379 ASSERT(Allocator::isAllocationAllowed()); 1379 ASSERT(Allocator::isAllocationAllowed());
1380 CHECK_LE(position, size()); 1380 RELEASE_ASSERT(position <= size());
1381 typename std::remove_reference<U>::type* data = &val; 1381 typename std::remove_reference<U>::type* data = &val;
1382 if (size() == capacity()) { 1382 if (size() == capacity()) {
1383 data = expandCapacity(size() + 1, data); 1383 data = expandCapacity(size() + 1, data);
1384 ASSERT(begin()); 1384 ASSERT(begin());
1385 } 1385 }
1386 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size + 1); 1386 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size + 1);
1387 T* spot = begin() + position; 1387 T* spot = begin() + position;
1388 TypeOperations::moveOverlapping(spot, end(), spot + 1); 1388 TypeOperations::moveOverlapping(spot, end(), spot + 1);
1389 new (NotNull, spot) T(std::forward<U>(*data)); 1389 new (NotNull, spot) T(std::forward<U>(*data));
1390 ++m_size; 1390 ++m_size;
(...skipping 23 matching lines...) Expand all
1414 template <typename T, size_t inlineCapacity, typename Allocator> 1414 template <typename T, size_t inlineCapacity, typename Allocator>
1415 template <typename U, size_t c, typename V> 1415 template <typename U, size_t c, typename V>
1416 inline void Vector<T, inlineCapacity, Allocator>::prependVector(const Vector<U, c, V>& val) 1416 inline void Vector<T, inlineCapacity, Allocator>::prependVector(const Vector<U, c, V>& val)
1417 { 1417 {
1418 insert(0, val.begin(), val.size()); 1418 insert(0, val.begin(), val.size());
1419 } 1419 }
1420 1420
1421 template <typename T, size_t inlineCapacity, typename Allocator> 1421 template <typename T, size_t inlineCapacity, typename Allocator>
1422 inline void Vector<T, inlineCapacity, Allocator>::remove(size_t position) 1422 inline void Vector<T, inlineCapacity, Allocator>::remove(size_t position)
1423 { 1423 {
1424 CHECK_LT(position, size()); 1424 RELEASE_ASSERT(position < size());
1425 T* spot = begin() + position; 1425 T* spot = begin() + position;
1426 spot->~T(); 1426 spot->~T();
1427 TypeOperations::moveOverlapping(spot + 1, end(), spot); 1427 TypeOperations::moveOverlapping(spot + 1, end(), spot);
1428 clearUnusedSlots(end() - 1, end()); 1428 clearUnusedSlots(end() - 1, end());
1429 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size - 1); 1429 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size - 1);
1430 --m_size; 1430 --m_size;
1431 } 1431 }
1432 1432
1433 template <typename T, size_t inlineCapacity, typename Allocator> 1433 template <typename T, size_t inlineCapacity, typename Allocator>
1434 inline void Vector<T, inlineCapacity, Allocator>::remove(size_t position, size_t length) 1434 inline void Vector<T, inlineCapacity, Allocator>::remove(size_t position, size_t length)
1435 { 1435 {
1436 ASSERT_WITH_SECURITY_IMPLICATION(position <= size()); 1436 ASSERT_WITH_SECURITY_IMPLICATION(position <= size());
1437 if (!length) 1437 if (!length)
1438 return; 1438 return;
1439 CHECK_LE(position + length, size()); 1439 RELEASE_ASSERT(position + length <= size());
1440 T* beginSpot = begin() + position; 1440 T* beginSpot = begin() + position;
1441 T* endSpot = beginSpot + length; 1441 T* endSpot = beginSpot + length;
1442 TypeOperations::destruct(beginSpot, endSpot); 1442 TypeOperations::destruct(beginSpot, endSpot);
1443 TypeOperations::moveOverlapping(endSpot, end(), beginSpot); 1443 TypeOperations::moveOverlapping(endSpot, end(), beginSpot);
1444 clearUnusedSlots(end() - length, end()); 1444 clearUnusedSlots(end() - length, end());
1445 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size - length); 1445 ANNOTATE_CHANGE_SIZE(begin(), capacity(), m_size, m_size - length);
1446 m_size -= length; 1446 m_size -= length;
1447 } 1447 }
1448 1448
1449 template <typename T, size_t inlineCapacity, typename Allocator> 1449 template <typename T, size_t inlineCapacity, typename Allocator>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 STATIC_ONLY(NeedsTracing); 1508 STATIC_ONLY(NeedsTracing);
1509 static const bool value = false; 1509 static const bool value = false;
1510 }; 1510 };
1511 #endif 1511 #endif
1512 1512
1513 } // namespace WTF 1513 } // namespace WTF
1514 1514
1515 using WTF::Vector; 1515 using WTF::Vector;
1516 1516
1517 #endif // WTF_Vector_h 1517 #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