diff --git a/xpcom/ds/nsISupportsArray.idl b/xpcom/ds/nsISupportsArray.idl index cdf7fbc3fb56..1a92cf2c1fa7 100644 --- a/xpcom/ds/nsISupportsArray.idl +++ b/xpcom/ds/nsISupportsArray.idl @@ -54,6 +54,9 @@ interface nsISupportsArray : nsICollection { nsISupportsArray clone(); + + [notxpcom] boolean RemoveElementsAt(in unsigned long aIndex, + in unsigned long aCount); }; %{C++ diff --git a/xpcom/ds/nsSupportsArray.cpp b/xpcom/ds/nsSupportsArray.cpp index 2a94f3e5bcbe..a37bcc2364bd 100644 --- a/xpcom/ds/nsSupportsArray.cpp +++ b/xpcom/ds/nsSupportsArray.cpp @@ -283,15 +283,16 @@ nsSupportsArray::ReplaceElementAt(nsISupports* aElement, uint32_t aIndex) } NS_IMETHODIMP_(bool) -nsSupportsArray::RemoveElementAt(uint32_t aIndex) +nsSupportsArray::RemoveElementsAt(uint32_t aIndex, uint32_t aCount) { - if (aIndex + 1 <= mCount) { - NS_IF_RELEASE(mArray[aIndex]); - - mCount -= 1; + if (aIndex + aCount <= mCount) { + for (uint32_t i = 0; i < aCount; i++) { + NS_IF_RELEASE(mArray[aIndex + i]); + } + mCount -= aCount; int32_t slide = (mCount - aIndex); if (0 < slide) { - ::memmove(mArray + aIndex, mArray + aIndex + 1, + ::memmove(mArray + aIndex, mArray + aIndex + aCount, slide * sizeof(nsISupports*)); } return true; diff --git a/xpcom/ds/nsSupportsArray.h b/xpcom/ds/nsSupportsArray.h index e927a63689eb..86f806de9d1a 100644 --- a/xpcom/ds/nsSupportsArray.h +++ b/xpcom/ds/nsSupportsArray.h @@ -82,7 +82,10 @@ public: ReplaceElementAt(nsISupports* aElement, uint32_t aIndex) override; MOZ_MUST_USE NS_IMETHOD_(bool) - RemoveElementAt(uint32_t aIndex) override; + RemoveElementAt(uint32_t aIndex) override + { + return RemoveElementsAt(aIndex, 1); + } MOZ_MUST_USE NS_IMETHOD DeleteElementAt(uint32_t aIndex) override { @@ -93,6 +96,9 @@ public: MOZ_MUST_USE NS_IMETHOD Clone(nsISupportsArray** aResult) override; + MOZ_MUST_USE NS_IMETHOD_(bool) + RemoveElementsAt(uint32_t aIndex, uint32_t aCount) override; + protected: void DeleteArray(void);