diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-11-28 23:10:30 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-11-28 23:10:30 +0100 |
commit | 088c3cf890cc2d96f2093e2116612cbf65bfaeea (patch) | |
tree | b4d3c68155f2de43432dd00c167d3029732be146 /xpcom/glue/nsTArray-inl.h | |
parent | ec3829bf7266ebec111f41268c6c491356576df1 (diff) | |
parent | fe11e14d3cfc2900facf152257acda87280b6cdc (diff) | |
download | UXP-088c3cf890cc2d96f2093e2116612cbf65bfaeea.tar UXP-088c3cf890cc2d96f2093e2116612cbf65bfaeea.tar.gz UXP-088c3cf890cc2d96f2093e2116612cbf65bfaeea.tar.lz UXP-088c3cf890cc2d96f2093e2116612cbf65bfaeea.tar.xz UXP-088c3cf890cc2d96f2093e2116612cbf65bfaeea.zip |
Merge branch 'master' into Sync-weave
Diffstat (limited to 'xpcom/glue/nsTArray-inl.h')
-rw-r--r-- | xpcom/glue/nsTArray-inl.h | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/xpcom/glue/nsTArray-inl.h b/xpcom/glue/nsTArray-inl.h index af57c9866..7e667a327 100644 --- a/xpcom/glue/nsTArray-inl.h +++ b/xpcom/glue/nsTArray-inl.h @@ -111,6 +111,23 @@ bool IsTwiceTheRequiredBytesRepresentableAsUint32(size_t aCapacity, template<class Alloc, class Copy> template<typename ActualAlloc> typename ActualAlloc::ResultTypeProxy +nsTArray_base<Alloc, Copy>::ExtendCapacity(size_type aLength, + size_type aCount, + size_type aElemSize) +{ + mozilla::CheckedInt<size_type> newLength = aLength; + newLength += aCount; + + if (!newLength.isValid()) { + return ActualAlloc::FailureResult(); + } + + return this->EnsureCapacity<ActualAlloc>(newLength.value(), aElemSize); +} + +template<class Alloc, class Copy> +template<typename ActualAlloc> +typename ActualAlloc::ResultTypeProxy nsTArray_base<Alloc, Copy>::EnsureCapacity(size_type aCapacity, size_type aElemSize) { @@ -275,26 +292,21 @@ nsTArray_base<Alloc, Copy>::ShiftData(index_type aStart, template<class Alloc, class Copy> template<typename ActualAlloc> -bool +typename ActualAlloc::ResultTypeProxy nsTArray_base<Alloc, Copy>::InsertSlotsAt(index_type aIndex, size_type aCount, size_type aElemSize, size_t aElemAlign) { MOZ_ASSERT(aIndex <= Length(), "Bogus insertion index"); - size_type newLen = Length() + aCount; - - EnsureCapacity<ActualAlloc>(newLen, aElemSize); - - // Check for out of memory conditions - if (Capacity() < newLen) { - return false; + if (!ActualAlloc::Successful(this->ExtendCapacity<ActualAlloc>(Length(), aCount, aElemSize))) { + return ActualAlloc::FailureResult(); } - + // Move the existing elements as needed. Note that this will // change our mLength, so no need to call IncrementLength. ShiftData<ActualAlloc>(aIndex, 0, aCount, aElemSize, aElemAlign); - return true; + return ActualAlloc::SuccessResult(); } // nsTArray_base::IsAutoArrayRestorer is an RAII class which takes |