summaryrefslogtreecommitdiff
path: root/mfbt
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2017-07-23 00:36:37 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2017-07-23 00:36:37 +0200
commitc48adc7a3b208d61703841ec7b7bc7a49cb24b8d (patch)
treec5ca149d69d96af88b8cd8324a856ce694227154 /mfbt
parent9a0d28e130fb4d2fb48d5acfac2b80c3cea35ba7 (diff)
downloadpalemoon-gre-c48adc7a3b208d61703841ec7b7bc7a49cb24b8d.tar.gz
JS - OOM (code clean up)
Diffstat (limited to 'mfbt')
-rw-r--r--mfbt/Vector.h16
-rw-r--r--mfbt/tests/TestBinarySearch.cpp14
2 files changed, 22 insertions, 8 deletions
diff --git a/mfbt/Vector.h b/mfbt/Vector.h
index 989841df8..712521cb0 100644
--- a/mfbt/Vector.h
+++ b/mfbt/Vector.h
@@ -507,6 +507,12 @@ public:
*/
void shrinkBy(size_t aIncr);
+ /**
+ * Destroy elements in the range [aNewLength, end()). Does not deallocate
+ * or unreserve storage for those elements.
+ */
+ void shrinkTo(size_t aNewLength);
+
/** Grow the vector by aIncr elements. */
bool growBy(size_t aIncr);
@@ -887,7 +893,7 @@ VectorBase<T, N, AP, TV>::reserve(size_t aRequest)
}
template<typename T, size_t N, class AP, class TV>
-inline void
+MOZ_ALWAYS_INLINE void
VectorBase<T, N, AP, TV>::shrinkBy(size_t aIncr)
{
MOZ_REENTRANCY_GUARD_ET_AL;
@@ -897,6 +903,14 @@ VectorBase<T, N, AP, TV>::shrinkBy(size_t aIncr)
}
template<typename T, size_t N, class AP, class TV>
+MOZ_ALWAYS_INLINE void
+VectorBase<T, N, AP, TV>::shrinkTo(size_t aNewLength)
+{
+ MOZ_ASSERT(aNewLength <= mLength);
+ shrinkBy(mLength - aNewLength);
+}
+
+template<typename T, size_t N, class AP, class TV>
MOZ_ALWAYS_INLINE bool
VectorBase<T, N, AP, TV>::growBy(size_t aIncr)
{
diff --git a/mfbt/tests/TestBinarySearch.cpp b/mfbt/tests/TestBinarySearch.cpp
index 334eb2110..44644bd3a 100644
--- a/mfbt/tests/TestBinarySearch.cpp
+++ b/mfbt/tests/TestBinarySearch.cpp
@@ -45,10 +45,10 @@ TestBinarySearch()
size_t m;
Vector<int> v1;
- v1.append(2);
- v1.append(4);
- v1.append(6);
- v1.append(8);
+ MOZ_RELEASE_ASSERT(v1.append(2));
+ MOZ_RELEASE_ASSERT(v1.append(4));
+ MOZ_RELEASE_ASSERT(v1.append(6));
+ MOZ_RELEASE_ASSERT(v1.append(8));
MOZ_RELEASE_ASSERT(!BinarySearch(v1, 0, v1.length(), 1, &m) && m == 0);
MOZ_RELEASE_ASSERT( BinarySearch(v1, 0, v1.length(), 2, &m) && m == 0);
@@ -78,9 +78,9 @@ TestBinarySearch()
MOZ_RELEASE_ASSERT(!BinarySearch(v2, 0, 0, 9, &m) && m == 0);
Vector<Person> v3;
- v3.append(Person(2, 42));
- v3.append(Person(4, 13));
- v3.append(Person(6, 360));
+ MOZ_RELEASE_ASSERT(v3.append(Person(2, 42)));
+ MOZ_RELEASE_ASSERT(v3.append(Person(4, 13)));
+ MOZ_RELEASE_ASSERT(v3.append(Person(6, 360)));
A(!BinarySearch(GetAge(v3), 0, v3.length(), 1, &m) && m == 0);
A( BinarySearch(GetAge(v3), 0, v3.length(), 2, &m) && m == 0);