From d09ce05d46a5b1651dbcd07268ea919c4f2cd8fc Mon Sep 17 00:00:00 2001 From: "kandrot%netscape.com" Date: Wed, 18 Jul 2001 00:29:20 +0000 Subject: [PATCH] Backing out this files last set of changes. git-svn-id: svn://10.0.0.236/trunk@99457 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/ds/nsSupportsArray.cpp | 44 ++++++++++------------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/mozilla/xpcom/ds/nsSupportsArray.cpp b/mozilla/xpcom/ds/nsSupportsArray.cpp index c7c0ae3bcb4..21f8df9191a 100644 --- a/mozilla/xpcom/ds/nsSupportsArray.cpp +++ b/mozilla/xpcom/ds/nsSupportsArray.cpp @@ -117,19 +117,12 @@ nsSupportsArray::operator=(nsISupportsArray const& aOther) NS_IMETHODIMP_(PRBool) nsSupportsArray::Equals(const nsISupportsArray* aOther) { - if (aOther) { - PRUint32 countOther; - nsresult rv = NS_CONST_CAST(nsISupportsArray*, aOther)->Count( &countOther ); - if (NS_FAILED( rv )) - return PR_FALSE; - - if (mCount == countOther) { + if (0 != aOther) { + const nsSupportsArray* other = (const nsSupportsArray*)aOther; + if (mCount == other->mCount) { PRUint32 aIndex = mCount; - nsCOMPtr other; while (0 < aIndex--) { - if (NS_FAILED( GetElementAt( aIndex, getter_AddRefs( other ) ) )) - return PR_FALSE; - if (mArray[aIndex] != other) { + if (mArray[aIndex] != other->mArray[aIndex]) { return PR_FALSE; } } @@ -295,21 +288,15 @@ nsSupportsArray::RemoveLastElement(const nsISupports* aElement) NS_IMETHODIMP_(PRBool) nsSupportsArray::AppendElements(nsISupportsArray* aElements) { - PRUint32 countElements; + nsSupportsArray* elements = (nsSupportsArray*)aElements; - if (!aElements) - return PR_FALSE; - - if (NS_FAILED( aElements->Count( &countElements ) )) - return PR_FALSE; - - if (0 < countElements) { - if (mArraySize < (mCount + countElements)) { // need to grow the array - PRUint32 count = mCount + countElements; + if (elements && (0 < elements->mCount)) { + if (mArraySize < (mCount + elements->mCount)) { // need to grow the array + PRUint32 count = mCount + elements->mCount; PRUint32 oldSize = mArraySize; - // growth is linear; consider geometric (e.g., doubling) to avoid the n^2 - // (amortized) cost we are paying to copy elements now - mArraySize += ((count - mArraySize + kGrowArrayBy - 1) / kGrowArrayBy) * kGrowArrayBy; + while (mArraySize < count) { // ick + mArraySize += kGrowArrayBy; + } nsISupports** oldArray = mArray; mArray = new nsISupports*[mArraySize]; if (0 == mArray) { // ran out of memory @@ -327,11 +314,10 @@ nsSupportsArray::AppendElements(nsISupportsArray* aElements) } } - PRUint32 i = 0; - for (i = 0; i < countElements; ++i, ++mCount) { - // use GetElementAt to copy and do AddRef for us - if (NS_FAILED( aElements->GetElementAt( i, mArray + mCount) )) - return PR_FALSE; + PRUint32 aIndex = 0; + while (aIndex < elements->mCount) { + NS_ADDREF(elements->mArray[aIndex]); + mArray[mCount++] = elements->mArray[aIndex++]; } return PR_TRUE; }