From d4f6772880d7fdbd7fc69b57aa68ea234c36243d Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Tue, 18 Oct 2016 11:36:36 -0700 Subject: [PATCH] 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 --- xpcom/ds/nsISupportsArray.idl | 4 ---- xpcom/ds/nsSupportsArray.cpp | 25 ++++++++----------------- xpcom/ds/nsSupportsArray.h | 9 --------- xpcom/glue/tests/gtest/TestArray.cpp | 15 ++++----------- 4 files changed, 12 insertions(+), 41 deletions(-) diff --git a/xpcom/ds/nsISupportsArray.idl b/xpcom/ds/nsISupportsArray.idl index b09eac2f1c68..1a92cf2c1fa7 100644 --- a/xpcom/ds/nsISupportsArray.idl +++ b/xpcom/ds/nsISupportsArray.idl @@ -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, diff --git a/xpcom/ds/nsSupportsArray.cpp b/xpcom/ds/nsSupportsArray.cpp index 8236fb560ed0..a37bcc2364bd 100644 --- a/xpcom/ds/nsSupportsArray.cpp +++ b/xpcom/ds/nsSupportsArray.cpp @@ -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; } diff --git a/xpcom/ds/nsSupportsArray.h b/xpcom/ds/nsSupportsArray.h index 237375d0bc86..86f806de9d1a 100644 --- a/xpcom/ds/nsSupportsArray.h +++ b/xpcom/ds/nsSupportsArray.h @@ -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); diff --git a/xpcom/glue/tests/gtest/TestArray.cpp b/xpcom/glue/tests/gtest/TestArray.cpp index 1e3654107562..5a07bbfc05d2 100644 --- a/xpcom/glue/tests/gtest/TestArray.cpp +++ b/xpcom/glue/tests/gtest/TestArray.cpp @@ -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);