зеркало из https://github.com/mozilla/gecko-dev.git
bug 856790 - make nsTArray::EnsureLengthAtleast() return void r=jlebar
This commit is contained in:
Родитель
900a3c725a
Коммит
369e88fcc0
|
@ -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) {
|
||||
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;
|
||||
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);
|
||||
// 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
|
||||
|
|
Загрузка…
Ссылка в новой задаче