Bug 1417279 - Remove an odd second case from nsArray::IndexOf. r=froydnj

Now that nsArray uses nsCOMArray under the hood, we don't have to do weird
ForwardEnumeration hacks to start IndexOf at a non-zero index.

MozReview-Commit-ID: 3ReDV0BT0hn

--HG--
extra : rebase_source : 399a988d00fabaa314eb7592b2aacf277a2ca477
This commit is contained in:
Blake Kaplan 2017-11-14 16:34:42 -08:00
parent 69bf04fc25
commit a64ff6d116

View File

@ -8,17 +8,6 @@
#include "nsArrayEnumerator.h"
#include "nsThreadUtils.h"
// used by IndexOf()
struct MOZ_STACK_CLASS findIndexOfClosure
{
// This is only used for pointer comparison, so we can just use a void*.
void* targetElement;
uint32_t startIndex;
uint32_t resultIndex;
};
static bool FindElementCallback(void* aElement, void* aClosure);
NS_INTERFACE_MAP_BEGIN(nsArray)
NS_INTERFACE_MAP_ENTRY(nsIArray)
NS_INTERFACE_MAP_ENTRY(nsIArrayExtensions)
@ -80,24 +69,12 @@ NS_IMETHODIMP
nsArrayBase::IndexOf(uint32_t aStartIndex, nsISupports* aElement,
uint32_t* aResult)
{
// optimize for the common case by forwarding to mArray
if (aStartIndex == 0) {
uint32_t idx = mArray.IndexOf(aElement);
if (idx == UINT32_MAX) {
return NS_ERROR_FAILURE;
}
*aResult = idx;
return NS_OK;
}
findIndexOfClosure closure = { aElement, aStartIndex, 0 };
bool notFound = mArray.EnumerateForwards(FindElementCallback, &closure);
if (notFound) {
int32_t idx = mArray.IndexOf(aElement, aStartIndex);
if (idx == -1) {
return NS_ERROR_FAILURE;
}
*aResult = closure.resultIndex;
*aResult = static_cast<uint32_t>(idx);
return NS_OK;
}
@ -160,25 +137,6 @@ nsArrayBase::GetElementAt(uint32_t aIndex, nsISupports** aResult)
return NS_OK;
}
//
// static helper routines
//
bool
FindElementCallback(void* aElement, void* aClosure)
{
findIndexOfClosure* closure = static_cast<findIndexOfClosure*>(aClosure);
nsISupports* element = static_cast<nsISupports*>(aElement);
// don't start searching until we're past the startIndex
if (closure->resultIndex >= closure->startIndex &&
element == closure->targetElement) {
return false; // stop! We found it
}
closure->resultIndex++;
return true;
}
nsresult
nsArrayBase::XPCOMConstructor(nsISupports* aOuter, const nsIID& aIID,
void** aResult)