From 677900e2012e83786896d5f804cd3a577e06d29d Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 14 Apr 2009 10:02:58 +0200 Subject: [PATCH] Bug 485782 - get rid of nsSupportsArray; r=sicking, sr=bsmedberg --- .../xul/templates/src/nsXULContentBuilder.cpp | 1 - docshell/shistory/src/nsSHEntry.h | 2 +- .../src/nsWebBrowserPersist.cpp | 17 ++++--- js/src/xpconnect/src/xpcprivate.h | 7 ++- js/src/xpconnect/src/xpcwrappedjsclass.cpp | 14 +++--- netwerk/base/src/nsIOService.h | 1 - netwerk/test/TestPageLoad.cpp | 17 ++----- widget/src/xpwidgets/nsPrintOptionsImpl.cpp | 2 +- xpcom/base/nsConsoleService.cpp | 30 ++++-------- .../xptinfo/src/xptiInterfaceInfoManager.cpp | 46 ++++++++----------- xpcom/reflect/xptinfo/src/xptiprivate.h | 5 +- 11 files changed, 55 insertions(+), 87 deletions(-) diff --git a/content/xul/templates/src/nsXULContentBuilder.cpp b/content/xul/templates/src/nsXULContentBuilder.cpp index 91dfea86656..707c96ff83a 100644 --- a/content/xul/templates/src/nsXULContentBuilder.cpp +++ b/content/xul/templates/src/nsXULContentBuilder.cpp @@ -60,7 +60,6 @@ #include "nsXULContentUtils.h" #include "nsXULElement.h" #include "nsXULTemplateBuilder.h" -#include "nsSupportsArray.h" #include "nsNodeInfoManager.h" #include "nsContentCreatorFunctions.h" #include "nsContentUtils.h" diff --git a/docshell/shistory/src/nsSHEntry.h b/docshell/shistory/src/nsSHEntry.h index 0b5a1551827..a966b97e8f2 100644 --- a/docshell/shistory/src/nsSHEntry.h +++ b/docshell/shistory/src/nsSHEntry.h @@ -56,7 +56,7 @@ #include "nsIEnumerator.h" #include "nsIHistoryEntry.h" #include "nsRect.h" -#include "nsSupportsArray.h" +#include "nsISupportsArray.h" #include "nsIMutationObserver.h" #include "nsExpirationTracker.h" #include "nsDocShellEditorData.h" diff --git a/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp b/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp index 19625b0af0b..85a576dbf17 100644 --- a/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp +++ b/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp @@ -1860,21 +1860,20 @@ void nsWebBrowserPersist::CleanupLocalFiles() // recursed through to ensure they are actually empty. PRBool isEmptyDirectory = PR_TRUE; - nsSupportsArray dirStack; - PRUint32 stackSize = 0; + nsCOMArray dirStack; + PRInt32 stackSize = 0; // Push the top level enum onto the stack nsCOMPtr pos; if (NS_SUCCEEDED(file->GetDirectoryEntries(getter_AddRefs(pos)))) - dirStack.AppendElement(pos); + dirStack.AppendObject(pos); - while (isEmptyDirectory && - NS_SUCCEEDED(dirStack.Count(&stackSize)) && stackSize > 0) + while (isEmptyDirectory && (stackSize = dirStack.Count())) { // Pop the last element nsCOMPtr curPos; - dirStack.GetElementAt(stackSize - 1, getter_AddRefs(curPos)); - dirStack.RemoveElementAt(stackSize - 1); + curPos = dirStack[stackSize-1]; + dirStack.RemoveObjectAt(stackSize - 1); // Test if the enumerator has any more files in it PRBool hasMoreElements = PR_FALSE; @@ -1908,9 +1907,9 @@ void nsWebBrowserPersist::CleanupLocalFiles() // Push parent enumerator followed by child enumerator nsCOMPtr childPos; childAsFile->GetDirectoryEntries(getter_AddRefs(childPos)); - dirStack.AppendElement(curPos); + dirStack.AppendObject(curPos); if (childPos) - dirStack.AppendElement(childPos); + dirStack.AppendObject(childPos); } dirStack.Clear(); diff --git a/js/src/xpconnect/src/xpcprivate.h b/js/src/xpconnect/src/xpcprivate.h index 15549b5bddc..42daba04aaa 100644 --- a/js/src/xpconnect/src/xpcprivate.h +++ b/js/src/xpconnect/src/xpcprivate.h @@ -108,7 +108,7 @@ #include "nsVariant.h" #include "nsIPropertyBag.h" #include "nsIProperty.h" -#include "nsSupportsArray.h" +#include "nsCOMArray.h" #include "nsTArray.h" #include "nsBaseHashtable.h" #include "nsHashKeys.h" @@ -2738,9 +2738,8 @@ public: JSBool AppendElement(nsISupports* element); private: - nsSupportsArray mArray; - PRUint32 mIndex; - PRUint32 mCount; + nsCOMArray mArray; + PRInt32 mIndex; }; /***************************************************************************/ diff --git a/js/src/xpconnect/src/xpcwrappedjsclass.cpp b/js/src/xpconnect/src/xpcwrappedjsclass.cpp index 11c315f5b21..36c0efdd05e 100644 --- a/js/src/xpconnect/src/xpcwrappedjsclass.cpp +++ b/js/src/xpconnect/src/xpcwrappedjsclass.cpp @@ -490,36 +490,36 @@ NS_IMETHODIMP xpcProperty::GetValue(nsIVariant * *aValue) NS_IMPL_ISUPPORTS1(xpcPropertyBagEnumerator, nsISimpleEnumerator) xpcPropertyBagEnumerator::xpcPropertyBagEnumerator(PRUint32 count) - : mIndex(0), mCount(0) + : mIndex(0) { - mArray.SizeTo(count); + mArray.SetCapacity(count); } JSBool xpcPropertyBagEnumerator::AppendElement(nsISupports* element) { - if(!mArray.AppendElement(element)) + if(!mArray.AppendObject(element)) return JS_FALSE; - mCount++; return JS_TRUE; } /* boolean hasMoreElements (); */ NS_IMETHODIMP xpcPropertyBagEnumerator::HasMoreElements(PRBool *_retval) { - *_retval = mIndex < mCount; + *_retval = mIndex < mArray.Count(); return NS_OK; } /* nsISupports getNext (); */ NS_IMETHODIMP xpcPropertyBagEnumerator::GetNext(nsISupports **_retval) { - if(!(mIndex < mCount)) + if(!(mIndex < mArray.Count())) { NS_ERROR("Bad nsISimpleEnumerator caller!"); return NS_ERROR_FAILURE; } - *_retval = mArray.ElementAt(mIndex++); + *_retval = mArray.ObjectAt(mIndex++); + NS_IF_ADDREF(*_retval); return *_retval ? NS_OK : NS_ERROR_FAILURE; } diff --git a/netwerk/base/src/nsIOService.h b/netwerk/base/src/nsIOService.h index 719e643d144..400b4d8792b 100644 --- a/netwerk/base/src/nsIOService.h +++ b/netwerk/base/src/nsIOService.h @@ -50,7 +50,6 @@ #include "nsURLHelper.h" #include "nsWeakPtr.h" #include "nsIURLParser.h" -#include "nsSupportsArray.h" #include "nsIObserver.h" #include "nsWeakReference.h" #include "nsINetUtil.h" diff --git a/netwerk/test/TestPageLoad.cpp b/netwerk/test/TestPageLoad.cpp index eb89a5cde4e..11905788951 100644 --- a/netwerk/test/TestPageLoad.cpp +++ b/netwerk/test/TestPageLoad.cpp @@ -47,7 +47,7 @@ #include "nsISupportsPrimitives.h" #include "prlong.h" #include "plstr.h" -#include "nsSupportsArray.h" +#include "nsCOMArray.h" #include "nsIComponentRegistrar.h" namespace TestPageLoad { @@ -68,7 +68,7 @@ nsresult auxLoad(char *uriBuf); static nsCString globalStream; //static char urlBuf[256]; static nsCOMPtr baseURI; -static nsCOMPtr uriList; +static nsCOMArray uriList; //Temp, should remove: static int numStart=0; @@ -317,20 +317,16 @@ nsresult auxLoad(char *uriBuf) } //Compare to see if exists - PRUint32 num; - uriList->Count(&num); PRBool equal; - nsCOMPtr uriTmp; - for(PRUint32 i = 0; i < num; i++) { - uriList->GetElementAt(i, getter_AddRefs(uriTmp)); - uri->Equals(uriTmp, &equal); + for(PRInt32 i = 0; i < uriList.Count(); i++) { + uri->Equals(uriList[i], &equal); if(equal) { printf("(duplicate, canceling) %s\n",uriBuf); return NS_OK; } } printf("\n"); - uriList->AppendElement(uri); + uriList.AppendObject(uri); rv = NS_NewChannel(getter_AddRefs(chan), uri, nsnull, nsnull, callbacks); RETURN_IF_FAILED(rv, "NS_NewChannel"); @@ -371,9 +367,6 @@ int main(int argc, char **argv) PRTime start, finish; - uriList = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); - RETURN_IF_FAILED(rv, "do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID)"); - printf("Loading necko ... \n"); nsCOMPtr chan; nsCOMPtr listener = new MyListener(); diff --git a/widget/src/xpwidgets/nsPrintOptionsImpl.cpp b/widget/src/xpwidgets/nsPrintOptionsImpl.cpp index 874c5e51169..728355c0c33 100644 --- a/widget/src/xpwidgets/nsPrintOptionsImpl.cpp +++ b/widget/src/xpwidgets/nsPrintOptionsImpl.cpp @@ -48,7 +48,7 @@ #include "nsISupportsPrimitives.h" #include "nsIWindowWatcher.h" #include "nsIDOMWindowInternal.h" -#include "nsSupportsArray.h" +#include "nsISupportsArray.h" #include "prprf.h" // For Prefs diff --git a/xpcom/base/nsConsoleService.cpp b/xpcom/base/nsConsoleService.cpp index 82a4b12a91a..1bcc8039bf3 100644 --- a/xpcom/base/nsConsoleService.cpp +++ b/xpcom/base/nsConsoleService.cpp @@ -46,7 +46,7 @@ #include "nsMemory.h" #include "nsIServiceManager.h" #include "nsIProxyObjectManager.h" -#include "nsSupportsArray.h" +#include "nsCOMArray.h" #include "nsThreadUtils.h" #include "nsConsoleService.h" @@ -111,10 +111,11 @@ nsConsoleService::Init() static PRBool snapshot_enum_func(nsHashKey *key, void *data, void* closure) { - nsISupportsArray *array = (nsISupportsArray *)closure; + nsCOMArray *array = + reinterpret_cast *>(closure); - // Copy each element into the temporary nsSupportsArray... - array->AppendElement((nsISupports*)data); + // Copy each element into the temporary nsCOMArray... + array->AppendObject((nsIConsoleListener*)data); return PR_TRUE; } @@ -125,7 +126,7 @@ nsConsoleService::LogMessage(nsIConsoleMessage *message) if (message == nsnull) return NS_ERROR_INVALID_ARG; - nsSupportsArray listenersSnapshot; + nsCOMArray listenersSnapshot; nsIConsoleMessage *retiredMessage; NS_ADDREF(message); // early, in case it's same as replaced below. @@ -167,12 +168,7 @@ nsConsoleService::LogMessage(nsIConsoleMessage *message) * when we only care about the recursive case. */ nsCOMPtr listener; - nsresult rv; - nsresult returned_rv; - PRUint32 snapshotCount; - rv = listenersSnapshot.Count(&snapshotCount); - if (NS_FAILED(rv)) - return rv; + PRInt32 snapshotCount = listenersSnapshot.Count(); { nsAutoLock lock(mLock); @@ -181,14 +177,8 @@ nsConsoleService::LogMessage(nsIConsoleMessage *message) mListening = PR_TRUE; } - returned_rv = NS_OK; - for (PRUint32 i = 0; i < snapshotCount; i++) { - rv = listenersSnapshot.GetElementAt(i, getter_AddRefs(listener)); - if (NS_FAILED(rv)) { - returned_rv = rv; - break; // fall thru to mListening restore code below. - } - listener->Observe(message); + for (PRInt32 i = 0; i < snapshotCount; i++) { + listenersSnapshot[i]->Observe(message); } { @@ -196,7 +186,7 @@ nsConsoleService::LogMessage(nsIConsoleMessage *message) mListening = PR_FALSE; } - return returned_rv; + return NS_OK; } NS_IMETHODIMP diff --git a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp index 90fb9a7defd..210cdcde54b 100644 --- a/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp +++ b/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp @@ -1973,49 +1973,48 @@ public: xptiAdditionalManagersEnumerator(); - PRBool SizeTo(PRUint32 likelyCount) {return mArray.SizeTo(likelyCount);} + PRBool SizeTo(PRUint32 likelyCount) {return mArray.SetCapacity(likelyCount);} PRBool AppendElement(nsIInterfaceInfoManager* element); private: ~xptiAdditionalManagersEnumerator() {} - nsSupportsArray mArray; - PRUint32 mIndex; - PRUint32 mCount; + nsCOMArray mArray; + PRInt32 mIndex; }; NS_IMPL_ISUPPORTS1(xptiAdditionalManagersEnumerator, nsISimpleEnumerator) xptiAdditionalManagersEnumerator::xptiAdditionalManagersEnumerator() - : mIndex(0), mCount(0) + : mIndex(0) { } PRBool xptiAdditionalManagersEnumerator::AppendElement(nsIInterfaceInfoManager* element) { - if(!mArray.AppendElement(static_cast(element))) + if(!mArray.AppendObject(element)) return PR_FALSE; - mCount++; return PR_TRUE; } /* boolean hasMoreElements (); */ NS_IMETHODIMP xptiAdditionalManagersEnumerator::HasMoreElements(PRBool *_retval) { - *_retval = mIndex < mCount; + *_retval = mIndex < mArray.Count(); return NS_OK; } /* nsISupports getNext (); */ NS_IMETHODIMP xptiAdditionalManagersEnumerator::GetNext(nsISupports **_retval) { - if(!(mIndex < mCount)) + if(!(mIndex < mArray.Count())) { NS_ERROR("Bad nsISimpleEnumerator caller!"); return NS_ERROR_FAILURE; } - *_retval = mArray.ElementAt(mIndex++); + *_retval = mArray.ObjectAt(mIndex++); + NS_IF_ADDREF(*_retval); return *_retval ? NS_OK : NS_ERROR_FAILURE; } @@ -2030,11 +2029,9 @@ NS_IMETHODIMP xptiInterfaceInfoManager::AddAdditionalManager(nsIInterfaceInfoMan static_cast(manager); { // scoped lock... nsAutoLock lock(mAdditionalManagersLock); - PRInt32 index; - nsresult rv = mAdditionalManagers.GetIndexOf(ptrToAdd, &index); - if(NS_FAILED(rv) || -1 != index) + if(mAdditionalManagers.IndexOf(ptrToAdd) != -1) return NS_ERROR_FAILURE; - if(!mAdditionalManagers.AppendElement(ptrToAdd)) + if(!mAdditionalManagers.AppendObject(ptrToAdd)) return NS_ERROR_OUT_OF_MEMORY; } return NS_OK; @@ -2049,7 +2046,7 @@ NS_IMETHODIMP xptiInterfaceInfoManager::RemoveAdditionalManager(nsIInterfaceInfo static_cast(manager); { // scoped lock... nsAutoLock lock(mAdditionalManagersLock); - if(!mAdditionalManagers.RemoveElement(ptrToRemove)) + if(!mAdditionalManagers.RemoveObject(ptrToRemove)) return NS_ERROR_FAILURE; } return NS_OK; @@ -2058,10 +2055,8 @@ NS_IMETHODIMP xptiInterfaceInfoManager::RemoveAdditionalManager(nsIInterfaceInfo /* PRBool hasAdditionalManagers (); */ NS_IMETHODIMP xptiInterfaceInfoManager::HasAdditionalManagers(PRBool *_retval) { - PRUint32 count; - nsresult rv = mAdditionalManagers.Count(&count); - *_retval = count != 0; - return rv; + *_retval = mAdditionalManagers.Count() > 0; + return NS_OK; } /* nsISimpleEnumerator enumerateAdditionalManagers (); */ @@ -2069,10 +2064,7 @@ NS_IMETHODIMP xptiInterfaceInfoManager::EnumerateAdditionalManagers(nsISimpleEnu { nsAutoLock lock(mAdditionalManagersLock); - PRUint32 count; - nsresult rv = mAdditionalManagers.Count(&count); - if(NS_FAILED(rv)) - return rv; + PRInt32 count = mAdditionalManagers.Count(); nsCOMPtr enumerator = new xptiAdditionalManagersEnumerator(); @@ -2081,10 +2073,9 @@ NS_IMETHODIMP xptiInterfaceInfoManager::EnumerateAdditionalManagers(nsISimpleEnu enumerator->SizeTo(count); - for(PRUint32 i = 0; i < count; /* i incremented in the loop body */) + for(PRInt32 i = 0; i < count; /* i incremented in the loop body */) { - nsCOMPtr raw = - dont_AddRef(mAdditionalManagers.ElementAt(i++)); + nsCOMPtr raw = mAdditionalManagers.ObjectAt(i++); if(!raw) return NS_ERROR_FAILURE; nsCOMPtr weakRef = do_QueryInterface(raw); @@ -2100,8 +2091,7 @@ NS_IMETHODIMP xptiInterfaceInfoManager::EnumerateAdditionalManagers(nsISimpleEnu else { // The manager is no more. Remove the element. - if(!mAdditionalManagers.RemoveElementAt(--i)) - return NS_ERROR_FAILURE; + mAdditionalManagers.RemoveObjectAt(--i); count--; } } diff --git a/xpcom/reflect/xptinfo/src/xptiprivate.h b/xpcom/reflect/xptinfo/src/xptiprivate.h index de36d65c3aa..f11043a73b7 100644 --- a/xpcom/reflect/xptinfo/src/xptiprivate.h +++ b/xpcom/reflect/xptinfo/src/xptiprivate.h @@ -66,9 +66,8 @@ #include "nsMemory.h" #include "nsISupportsArray.h" -#include "nsSupportsArray.h" +#include "nsCOMArray.h" #include "nsInt64.h" - #include "nsQuickSort.h" #include "nsXPIDLString.h" @@ -968,7 +967,7 @@ private: PRLock* mAutoRegLock; PRMonitor* mInfoMonitor; PRLock* mAdditionalManagersLock; - nsSupportsArray mAdditionalManagers; + nsCOMArray mAdditionalManagers; nsCOMPtr mSearchPath; };