Backed out changeset 63208c26bfc3 (bug 1308317)

This commit is contained in:
Carsten "Tomcat" Book 2016-10-14 14:58:46 +02:00
parent 638c43c71b
commit 46b2fe93c0
3 changed files with 34 additions and 0 deletions

View File

@ -63,6 +63,9 @@ interface nsISupportsArray : nsICollection {
nsISupportsArray clone();
[notxpcom] boolean MoveElement(in long aFrom,
in long aTo);
[notxpcom] boolean RemoveElementsAt(in unsigned long aIndex,
in unsigned long aCount);

View File

@ -360,6 +360,36 @@ nsSupportsArray::RemoveLastElement(const nsISupports* aElement)
return false;
}
NS_IMETHODIMP_(bool)
nsSupportsArray::MoveElement(int32_t aFrom, int32_t aTo)
{
nsISupports* tempElement;
if (aTo == aFrom) {
return true;
}
if (aTo < 0 || aFrom < 0 ||
(uint32_t)aTo >= mCount || (uint32_t)aFrom >= mCount) {
// can't extend the array when moving an element. Also catches mImpl = null
return false;
}
tempElement = mArray[aFrom];
if (aTo < aFrom) {
// Moving one element closer to the head; the elements inbetween move down
::memmove(mArray + aTo + 1, mArray + aTo,
(aFrom - aTo) * sizeof(mArray[0]));
mArray[aTo] = tempElement;
} else { // already handled aFrom == aTo
// Moving one element closer to the tail; the elements inbetween move up
::memmove(mArray + aFrom, mArray + aFrom + 1,
(aTo - aFrom) * sizeof(mArray[0]));
mArray[aTo] = tempElement;
}
return true;
}
NS_IMETHODIMP
nsSupportsArray::Clear(void)

View File

@ -56,6 +56,7 @@ public:
}
// XXX this is badly named - should be RemoveFirstElement
MOZ_MUST_USE NS_IMETHOD RemoveElement(nsISupports* aElement) override;
MOZ_MUST_USE NS_IMETHOD_(bool) MoveElement(int32_t aFrom, int32_t aTo) override;
NS_IMETHOD Enumerate(nsIEnumerator** aResult) override;
NS_IMETHOD Clear(void) override;