Bug 643885 - Part 1: Add the new RemoveObjectsAt API to nsCOMArray; r=bsmedberg

This commit is contained in:
Ehsan Akhgari
2011-04-14 10:18:02 -04:00
parent df6193abb3
commit 1bb15589a7
3 changed files with 80 additions and 10 deletions

View File

@@ -140,6 +140,25 @@ nsCOMArray_base::RemoveObjectAt(PRInt32 aIndex)
return PR_FALSE;
}
PRBool
nsCOMArray_base::RemoveObjectsAt(PRInt32 aIndex, PRInt32 aCount)
{
if (PRUint32(aIndex) + PRUint32(aCount) <= PRUint32(Count())) {
nsVoidArray elementsToDestroy(aCount);
for (PRInt32 i = 0; i < aCount; ++i) {
elementsToDestroy.InsertElementAt(mArray.FastElementAt(aIndex + i), i);
}
PRBool result = mArray.RemoveElementsAt(aIndex, aCount);
for (PRInt32 i = 0; i < aCount; ++i) {
nsISupports* element = static_cast<nsISupports*> (elementsToDestroy.FastElementAt(i));
NS_IF_RELEASE(element);
}
return result;
}
return PR_FALSE;
}
// useful for destructors
PRBool
ReleaseObjects(void* aElement, void*)