bug 856790 - make nsTArray::EnsureLengthAtleast() return void r=jlebar

This commit is contained in:
Trevor Saunders 2013-04-01 16:42:54 -04:00
Родитель 900a3c725a
Коммит 369e88fcc0
2 изменённых файлов: 20 добавлений и 11 удалений

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

@ -169,14 +169,13 @@ nsCOMArray_base::InsertElementsAt(uint32_t aIndex, nsISupports* const* aElements
bool
nsCOMArray_base::ReplaceObjectAt(nsISupports* aObject, int32_t aIndex)
{
bool result = mArray.EnsureLengthAtLeast(aIndex + 1);
if (result) {
mArray.EnsureLengthAtLeast(aIndex + 1);
nsISupports *oldObject = mArray[aIndex];
// Make sure to addref first, in case aObject == oldObject
NS_IF_ADDREF(mArray[aIndex] = aObject);
NS_IF_RELEASE(oldObject);
}
return result;
// XXX make this return void
return true;
}
bool

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

@ -131,6 +131,10 @@ struct nsTArrayFallibleAllocatorBase
static ResultTypeProxy FailureResult() {
return false;
}
static ResultType ConvertBoolToResultType(bool aValue) {
return aValue;
}
};
struct nsTArrayInfallibleAllocatorBase
@ -153,6 +157,12 @@ struct nsTArrayInfallibleAllocatorBase
NS_RUNTIMEABORT("Infallible nsTArray should never fail");
return ResultTypeProxy();
}
static ResultType ConvertBoolToResultType(bool aValue) {
if (!aValue) {
NS_RUNTIMEABORT("infallible nsTArray should never convert false to ResultType");
}
}
};
#if defined(MOZALLOC_HAVE_XMALLOC)
@ -1215,12 +1225,12 @@ public:
// constructor.
// @param minLen The desired minimum length of this array.
// @return True if the operation succeeded; false otherwise.
bool EnsureLengthAtLeast(size_type minLen) {
typename Alloc::ResultType EnsureLengthAtLeast(size_type minLen) {
size_type oldLen = Length();
if (minLen > oldLen) {
return InsertElementsAt(oldLen, minLen - oldLen) != nullptr;
return Alloc::ConvertBoolToResultType(!!InsertElementsAt(oldLen, minLen - oldLen));
}
return true;
return Alloc::ConvertBoolToResultType(true);
}
// This method inserts elements into the array, constructing