Bug 968520 - Always use fallible allocator with nsTArray_base::ShrinkCapacity. r=froydnj

We don't need infallible allocation here because failure to shrink the
capacity will leave the array unchanged.
This commit is contained in:
Birunthan Mohanathas 2015-11-02 07:53:27 +02:00
parent ae9f709353
commit 4c863353ab
2 changed files with 9 additions and 9 deletions

View File

@ -196,8 +196,9 @@ nsTArray_base<Alloc, Copy>::EnsureCapacity(size_type aCapacity,
return ActualAlloc::SuccessResult();
}
// We don't need use Alloc template parameter specified here because failure to
// shrink the capacity will leave the array unchanged.
template<class Alloc, class Copy>
template<typename ActualAlloc>
void
nsTArray_base<Alloc, Copy>::ShrinkCapacity(size_type aElemSize,
size_t aElemAlign)
@ -219,20 +220,20 @@ nsTArray_base<Alloc, Copy>::ShrinkCapacity(size_type aElemSize,
header->mLength = length;
Copy::CopyElements(header + 1, mHdr + 1, length, aElemSize);
ActualAlloc::Free(mHdr);
nsTArrayFallibleAllocator::Free(mHdr);
mHdr = header;
return;
}
if (length == 0) {
MOZ_ASSERT(!IsAutoArray(), "autoarray should have fit 0 elements");
ActualAlloc::Free(mHdr);
nsTArrayFallibleAllocator::Free(mHdr);
mHdr = EmptyHdr();
return;
}
size_type size = sizeof(Header) + length * aElemSize;
void* ptr = ActualAlloc::Realloc(mHdr, size);
void* ptr = nsTArrayFallibleAllocator::Realloc(mHdr, size);
if (!ptr) {
return;
}
@ -257,7 +258,7 @@ nsTArray_base<Alloc, Copy>::ShiftData(index_type aStart,
// Compute the resulting length of the array
mHdr->mLength += aNewLen - aOldLen;
if (mHdr->mLength == 0) {
ShrinkCapacity<ActualAlloc>(aElemSize, aElemAlign);
ShrinkCapacity(aElemSize, aElemAlign);
} else {
// Maybe nothing needs to be shifted
if (num == 0) {

View File

@ -382,10 +382,10 @@ protected:
typename ActualAlloc::ResultTypeProxy EnsureCapacity(size_type aCapacity,
size_type aElemSize);
// Resize the storage to the minimum required amount.
// Tries to resize the storage to the minimum required amount. If this fails,
// the array is left as-is.
// @param aElemSize The size of an array element.
// @param aElemAlign The alignment in bytes of an array element.
template<typename ActualAlloc>
void ShrinkCapacity(size_type aElemSize, size_t aElemAlign);
// This method may be called to resize a "gap" in the array by shifting
@ -1885,8 +1885,7 @@ public:
// This method may be called to minimize the memory used by this array.
void Compact()
{
this->template ShrinkCapacity<Alloc>(sizeof(elem_type),
MOZ_ALIGNOF(elem_type));
ShrinkCapacity(sizeof(elem_type), MOZ_ALIGNOF(elem_type));
}
//