Bug 485782 - get rid of nsSupportsArray; r=sicking, sr=bsmedberg

This commit is contained in:
Arpad Borsos 2009-04-14 10:02:58 +02:00
Родитель 7115da12a4
Коммит 677900e201
11 изменённых файлов: 55 добавлений и 87 удалений

Просмотреть файл

@ -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"

Просмотреть файл

@ -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"

Просмотреть файл

@ -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<nsISimpleEnumerator> dirStack;
PRInt32 stackSize = 0;
// Push the top level enum onto the stack
nsCOMPtr<nsISimpleEnumerator> 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<nsISimpleEnumerator> 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<nsISimpleEnumerator> childPos;
childAsFile->GetDirectoryEntries(getter_AddRefs(childPos));
dirStack.AppendElement(curPos);
dirStack.AppendObject(curPos);
if (childPos)
dirStack.AppendElement(childPos);
dirStack.AppendObject(childPos);
}
dirStack.Clear();

Просмотреть файл

@ -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<nsISupports> mArray;
PRInt32 mIndex;
};
/***************************************************************************/

Просмотреть файл

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

Просмотреть файл

@ -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"

Просмотреть файл

@ -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<nsIURI> baseURI;
static nsCOMPtr<nsISupportsArray> uriList;
static nsCOMArray<nsIURI> 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<nsIURI> 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<nsIChannel> chan;
nsCOMPtr<nsIStreamListener> listener = new MyListener();

Просмотреть файл

@ -48,7 +48,7 @@
#include "nsISupportsPrimitives.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindowInternal.h"
#include "nsSupportsArray.h"
#include "nsISupportsArray.h"
#include "prprf.h"
// For Prefs

Просмотреть файл

@ -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<nsIConsoleListener> *array =
reinterpret_cast<nsCOMArray<nsIConsoleListener> *>(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<nsIConsoleListener> 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<nsIConsoleListener> 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

Просмотреть файл

@ -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<nsISupports> 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<nsISupports*>(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<nsISupports*>(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<nsISupports*>(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<xptiAdditionalManagersEnumerator> 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<nsISupports> raw =
dont_AddRef(mAdditionalManagers.ElementAt(i++));
nsCOMPtr<nsISupports> raw = mAdditionalManagers.ObjectAt(i++);
if(!raw)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIWeakReference> 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--;
}
}

Просмотреть файл

@ -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<nsISupports> mAdditionalManagers;
nsCOMPtr<nsISupportsArray> mSearchPath;
};