bug 856696 - make nsTArray::SwapElements() return void r=jlebar

This commit is contained in:
Trevor Saunders 2013-04-01 13:43:34 -04:00
Родитель 9c14887d75
Коммит b81241eb2d
2 изменённых файлов: 14 добавлений и 11 удалений

Просмотреть файл

@ -300,7 +300,7 @@ nsTArray_base<Alloc>::IsAutoArrayRestorer::~IsAutoArrayRestorer() {
template<class Alloc>
template<class Allocator>
bool
typename Alloc::ResultTypeProxy
nsTArray_base<Alloc>::SwapArrayElements(nsTArray_base<Allocator>& other,
size_type elemSize,
size_t elemAlign) {
@ -321,14 +321,14 @@ nsTArray_base<Alloc>::SwapArrayElements(nsTArray_base<Allocator>& other,
if (!EnsureNotUsingAutoArrayBuffer(elemSize) ||
!other.EnsureNotUsingAutoArrayBuffer(elemSize)) {
return false;
return Alloc::FailureResult();
}
Header *temp = mHdr;
mHdr = other.mHdr;
other.mHdr = temp;
return true;
return Alloc::SuccessResult();
}
// Swap the two arrays using memcpy, since at least one is using an auto
@ -344,7 +344,7 @@ nsTArray_base<Alloc>::SwapArrayElements(nsTArray_base<Allocator>& other,
if (!Alloc::Successful(EnsureCapacity(other.Length(), elemSize)) ||
!Allocator::Successful(other.EnsureCapacity(Length(), elemSize))) {
return false;
return Alloc::FailureResult();
}
// The EnsureCapacity calls above shouldn't have caused *both* arrays to
@ -372,7 +372,7 @@ nsTArray_base<Alloc>::SwapArrayElements(nsTArray_base<Allocator>& other,
// could, in theory, allocate a huge AutoTArray on the heap.)
nsAutoArrayBase<nsTArray_Impl<uint8_t, Alloc>, 64> temp;
if (!Alloc::Successful(temp.EnsureCapacity(smallerLength, elemSize))) {
return false;
return Alloc::FailureResult();
}
memcpy(temp.Elements(), smallerElements, smallerLength * elemSize);
@ -387,7 +387,7 @@ nsTArray_base<Alloc>::SwapArrayElements(nsTArray_base<Allocator>& other,
mHdr->mLength = other.Length();
other.mHdr->mLength = tempLength;
return true;
return Alloc::SuccessResult();
}
template<class Alloc>

Просмотреть файл

@ -424,9 +424,10 @@ protected:
protected:
template<class Allocator>
bool SwapArrayElements(nsTArray_base<Allocator>& other,
size_type elemSize,
size_t elemAlign);
typename Alloc::ResultTypeProxy
SwapArrayElements(nsTArray_base<Allocator>& other,
size_type elemSize,
size_t elemAlign);
// This is an RAII class used in SwapArrayElements.
class IsAutoArrayRestorer {
@ -1157,8 +1158,10 @@ public:
// This method causes the elements contained in this array and the given
// array to be swapped.
template<class Allocator>
bool SwapElements(nsTArray_Impl<E, Allocator>& other) {
return this->SwapArrayElements(other, sizeof(elem_type), MOZ_ALIGNOF(elem_type));
typename Alloc::ResultType
SwapElements(nsTArray_Impl<E, Allocator>& other) {
return Alloc::Result(this->SwapArrayElements(other, sizeof(elem_type),
MOZ_ALIGNOF(elem_type)));
}
//