mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1308317 - Part 6: Remove nsSupportsArray::GetIndexOfStartingAt. r=froydnj
This removes the scriptable method |GetIndexOfStartingAt| which is unused in our codebase and turns up no references in the plugins repo. This allows to remove the non-scriptable |IndexOfStartingAt| which is folded into |IndexOf|. MozReview-Commit-ID: 2ADz5mLIvMU
This commit is contained in:
parent
08e653d2cf
commit
b3bce28ad5
@ -34,14 +34,10 @@ class nsISupportsArray;
|
||||
interface nsISupportsArray : nsICollection {
|
||||
|
||||
[notxpcom] long IndexOf([const] in nsISupports aPossibleElement);
|
||||
[notxpcom] long IndexOfStartingAt([const] in nsISupports aPossibleElement,
|
||||
in unsigned long aStartIndex);
|
||||
[notxpcom] long LastIndexOf([const] in nsISupports aPossibleElement);
|
||||
|
||||
// xpcom-compatible versions
|
||||
long GetIndexOf(in nsISupports aPossibleElement);
|
||||
long GetIndexOfStartingAt(in nsISupports aPossibleElement,
|
||||
in unsigned long aStartIndex);
|
||||
long GetLastIndexOf(in nsISupports aPossibleElement);
|
||||
|
||||
[notxpcom] boolean InsertElementAt(in nsISupports aElement,
|
||||
|
@ -209,23 +209,14 @@ nsSupportsArray::GetElementAt(uint32_t aIndex, nsISupports** aOutPtr)
|
||||
NS_IMETHODIMP_(int32_t)
|
||||
nsSupportsArray::IndexOf(const nsISupports* aPossibleElement)
|
||||
{
|
||||
return IndexOfStartingAt(aPossibleElement, 0);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(int32_t)
|
||||
nsSupportsArray::IndexOfStartingAt(const nsISupports* aPossibleElement,
|
||||
uint32_t aStartIndex)
|
||||
{
|
||||
if (aStartIndex < mCount) {
|
||||
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
|
||||
const nsISupports** ep = (start + aStartIndex);
|
||||
const nsISupports** end = (start + mCount);
|
||||
while (ep < end) {
|
||||
if (aPossibleElement == *ep) {
|
||||
return (ep - start);
|
||||
}
|
||||
ep++;
|
||||
const nsISupports** start = (const nsISupports**)mArray; // work around goofy compiler behavior
|
||||
const nsISupports** ep = start;
|
||||
const nsISupports** end = (start + mCount);
|
||||
while (ep < end) {
|
||||
if (aPossibleElement == *ep) {
|
||||
return (ep - start);
|
||||
}
|
||||
ep++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -312,7 +303,7 @@ nsSupportsArray::RemoveElementsAt(uint32_t aIndex, uint32_t aCount)
|
||||
NS_IMETHODIMP
|
||||
nsSupportsArray::RemoveElement(nsISupports* aElement)
|
||||
{
|
||||
int32_t theIndex = IndexOfStartingAt(aElement, 0);
|
||||
int32_t theIndex = IndexOf(aElement);
|
||||
if (theIndex >= 0) {
|
||||
return RemoveElementAt(theIndex) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -61,8 +61,6 @@ public:
|
||||
|
||||
// nsISupportsArray methods:
|
||||
NS_IMETHOD_(int32_t) IndexOf(const nsISupports* aPossibleElement) override;
|
||||
NS_IMETHOD_(int32_t) IndexOfStartingAt(const nsISupports* aPossibleElement,
|
||||
uint32_t aStartIndex = 0) override;
|
||||
NS_IMETHOD_(int32_t) LastIndexOf(const nsISupports* aPossibleElement) override;
|
||||
|
||||
NS_IMETHOD GetIndexOf(nsISupports* aPossibleElement, int32_t* aResult) override
|
||||
@ -71,13 +69,6 @@ public:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetIndexOfStartingAt(nsISupports* aPossibleElement,
|
||||
uint32_t aStartIndex, int32_t* aResult) override
|
||||
{
|
||||
*aResult = IndexOfStartingAt(aPossibleElement, aStartIndex);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetLastIndexOf(nsISupports* aPossibleElement, int32_t* aResult) override
|
||||
{
|
||||
*aResult = LastIndexOf(aPossibleElement);
|
||||
|
@ -119,19 +119,12 @@ TEST(Array, main)
|
||||
|
||||
|
||||
// test IndexOf && LastIndexOf
|
||||
int32_t expectedIndex[5] = {0, 4, 6, 12, -1};
|
||||
int32_t count = 0;
|
||||
int32_t expectedIndex = 0;
|
||||
int32_t index = array->IndexOf(foo);
|
||||
EXPECT_EQ(index, expectedIndex[count]);
|
||||
while (-1 != index) {
|
||||
count++;
|
||||
index = array->IndexOfStartingAt(foo, index + 1);
|
||||
if (-1 != index)
|
||||
EXPECT_EQ(index, expectedIndex[count]);
|
||||
}
|
||||
EXPECT_EQ(index, expectedIndex);
|
||||
expectedIndex = 12;
|
||||
index = array->LastIndexOf(foo);
|
||||
count--;
|
||||
EXPECT_EQ(index, expectedIndex[count]);
|
||||
EXPECT_EQ(index, expectedIndex);
|
||||
|
||||
// test ReplaceElementAt
|
||||
array->ReplaceElementAt(foo, 8);
|
||||
|
Loading…
Reference in New Issue
Block a user