Backing out this files last set of changes.

git-svn-id: svn://10.0.0.236/trunk@99457 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
kandrot%netscape.com
2001-07-18 00:29:20 +00:00
parent 545d03af93
commit d09ce05d46

View File

@@ -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<nsISupports> 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;
}