Bug 474369 - get rid of nsVoidArray, remaining parts; r=bz, sr=dbaron

This commit is contained in:
Arpad Borsos 2009-05-07 17:15:26 +02:00
parent 3618b7200e
commit 6a70c37113
33 changed files with 276 additions and 443 deletions

View File

@ -42,7 +42,6 @@
#include "nsAutoPtr.h"
#include "nsCOMPtr.h"
#include "nsVoidArray.h"
#include "nsHashtable.h"
#include "nsJSPrincipals.h"
#include "nsTArray.h"

View File

@ -49,7 +49,6 @@
#include "nsIProtocolHandler.h"
#include "nsNetUtil.h"
#include "nsJSPrincipals.h"
#include "nsVoidArray.h"
#include "nsHashtable.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"

View File

@ -266,7 +266,7 @@ CanLoadResource(nsIURI* aResourceURI)
nsChromeRegistry::ProviderEntry*
nsChromeRegistry::nsProviderArray::GetProvider(const nsACString& aPreferred, MatchType aType)
{
PRInt32 i = mArray.Count();
PRInt32 i = mArray.Length();
if (!i)
return nsnull;
@ -274,7 +274,7 @@ nsChromeRegistry::nsProviderArray::GetProvider(const nsACString& aPreferred, Mat
ProviderEntry* entry;
while (i--) {
entry = reinterpret_cast<ProviderEntry*>(mArray[i]);
entry = &mArray[i];
if (aPreferred.Equals(entry->provider))
return entry;
@ -329,32 +329,21 @@ nsChromeRegistry::nsProviderArray::SetBase(const nsACString& aProvider, nsIURI*
}
// no existing entries, add a new one
provider = new ProviderEntry(aProvider, aBaseURL);
if (!provider)
return; // It's safe to silently fail on OOM
mArray.AppendElement(provider);
mArray.AppendElement(ProviderEntry(aProvider, aBaseURL));
}
void
nsChromeRegistry::nsProviderArray::EnumerateToArray(nsTArray<nsCString> *a)
{
PRInt32 i = mArray.Count();
PRInt32 i = mArray.Length();
while (i--) {
ProviderEntry *entry = reinterpret_cast<ProviderEntry*>(mArray[i]);
a->AppendElement(entry->provider);
a->AppendElement(mArray[i].provider);
}
}
void
nsChromeRegistry::nsProviderArray::Clear()
{
PRInt32 i = mArray.Count();
while (i--) {
ProviderEntry* entry = reinterpret_cast<ProviderEntry*>(mArray[i]);
delete entry;
}
mArray.Clear();
}

View File

@ -52,7 +52,6 @@
#include "nsString.h"
#include "nsTHashtable.h"
#include "nsURIHashKey.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsInterfaceHashtable.h"
@ -171,7 +170,7 @@ public:
private:
ProviderEntry* GetProvider(const nsACString& aPreferred, MatchType aType);
nsVoidArray mArray;
nsTArray<ProviderEntry> mArray;
};
struct PackageEntry : public PLDHashEntryHdr

View File

@ -39,7 +39,6 @@
#include "nsMorkReader.h"
#include "prio.h"
#include "nsNetUtil.h"
#include "nsVoidArray.h"
// A FixedString implementation that can hold 2 80-character lines
class nsCLineString : public nsFixedCString

View File

@ -813,9 +813,9 @@ void
nsDocShell::DestroyChildren()
{
nsCOMPtr<nsIDocShellTreeItem> shell;
PRInt32 n = mChildList.Count();
for (PRInt32 i = 0; i < n; i++) {
shell = do_QueryInterface(ChildAt(i));
PRUint32 n = mChildList.Length();
for (PRUint32 i = 0; i < n; i++) {
shell = do_QueryInterface(mChildList[i]);
NS_ASSERTION(shell, "docshell has null child");
if (shell) {
@ -1474,10 +1474,10 @@ nsDocShell::FirePageHideNotification(PRBool aIsUnload)
mContentViewer->PageHide(aIsUnload);
nsAutoTArray<nsCOMPtr<nsIDocShell>, 8> kids;
PRInt32 i, n = mChildList.Count();
PRUint32 i, n = mChildList.Length();
kids.SetCapacity(n);
for (i = 0; i < n; i++) {
kids.AppendElement(do_QueryInterface(ChildAt(i)));
kids.AppendElement(do_QueryInterface(mChildList[i]));
}
n = kids.Length();
@ -2129,9 +2129,9 @@ nsDocShell::HistoryPurged(PRInt32 aNumEntries)
mPreviousTransIndex = PR_MAX(-1, mPreviousTransIndex - aNumEntries);
mLoadedTransIndex = PR_MAX(0, mLoadedTransIndex - aNumEntries);
PRInt32 count = mChildList.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
PRUint32 count = mChildList.Length();
for (PRUint32 i = 0; i < count; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(mChildList[i]);
if (shell) {
shell->HistoryPurged(aNumEntries);
}
@ -2834,9 +2834,9 @@ nsDocShell::SetTreeOwner(nsIDocShellTreeOwner * aTreeOwner)
mTreeOwner = aTreeOwner; // Weak reference per API
PRInt32 i, n = mChildList.Count();
PRUint32 i, n = mChildList.Length();
for (i = 0; i < n; i++) {
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryInterface(ChildAt(i));
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryInterface(mChildList[i]);
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
PRInt32 childType = ~mItemType; // Set it to not us in case the get fails
child->GetItemType(&childType); // We don't care if this fails, if it does we won't set the owner
@ -2869,7 +2869,7 @@ NS_IMETHODIMP
nsDocShell::GetChildCount(PRInt32 * aChildCount)
{
NS_ENSURE_ARG_POINTER(aChildCount);
*aChildCount = mChildList.Count();
*aChildCount = mChildList.Length();
return NS_OK;
}
@ -2904,7 +2904,7 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
nsresult res = AddChildLoader(childAsDocLoader);
NS_ENSURE_SUCCESS(res, res);
NS_ASSERTION(mChildList.Count() > 0,
NS_ASSERTION(!mChildList.IsEmpty(),
"child list must not be empty after a successful add");
// Set the child's index in the parent's children list
@ -2919,11 +2919,11 @@ nsDocShell::AddChild(nsIDocShellTreeItem * aChild)
nsCOMPtr<nsIDOMDocument> domDoc =
do_GetInterface(GetAsSupports(this));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
PRUint32 offset = mChildList.Count() - 1;
PRUint32 offset = mChildList.Length() - 1;
if (doc) {
PRUint32 oldChildCount = offset; // Current child count - 1
for (PRUint32 i = 0; i < oldChildCount; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
nsCOMPtr<nsIDocShell> child = do_QueryInterface(mChildList[i]);
if (doc->FrameLoaderScheduledToBeFinalized(child)) {
--offset;
}
@ -3043,12 +3043,12 @@ nsDocShell::GetChildAt(PRInt32 aIndex, nsIDocShellTreeItem ** aChild)
if (aIndex < 0) {
NS_WARNING("Negative index passed to GetChildAt");
}
else if (aIndex >= mChildList.Count()) {
else if (PRUint32(aIndex) >= mChildList.Length()) {
NS_WARNING("Too large an index passed to GetChildAt");
}
#endif
nsIDocumentLoader* child = SafeChildAt(aIndex);
nsIDocumentLoader* child = mChildList.SafeElementAt(aIndex);
NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED);
return CallQueryInterface(child, aChild);
@ -3070,9 +3070,9 @@ nsDocShell::FindChildWithName(const PRUnichar * aName,
return NS_OK;
nsXPIDLString childName;
PRInt32 i, n = mChildList.Count();
PRUint32 i, n = mChildList.Length();
for (i = 0; i < n; i++) {
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryInterface(ChildAt(i));
nsCOMPtr<nsIDocShellTreeItem> child = do_QueryInterface(mChildList[i]);
NS_ENSURE_TRUE(child, NS_ERROR_FAILURE);
PRInt32 childType;
child->GetItemType(&childType);
@ -3970,10 +3970,10 @@ nsDocShell::Stop(PRUint32 aStopFlags)
Stop();
}
PRInt32 n;
PRInt32 count = mChildList.Count();
PRUint32 n;
PRUint32 count = mChildList.Length();
for (n = 0; n < count; n++) {
nsCOMPtr<nsIWebNavigation> shellAsNav(do_QueryInterface(ChildAt(n)));
nsCOMPtr<nsIWebNavigation> shellAsNav(do_QueryInterface(mChildList[n]));
if (shellAsNav)
shellAsNav->Stop(aStopFlags);
}
@ -5408,10 +5408,10 @@ nsDocShell::SuspendRefreshURIs()
}
// Suspend refresh URIs for our child shells as well.
PRInt32 n = mChildList.Count();
PRUint32 n = mChildList.Length();
for (PRInt32 i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
for (PRUint32 i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(mChildList[i]);
if (shell)
shell->SuspendRefreshURIs();
}
@ -5425,10 +5425,10 @@ nsDocShell::ResumeRefreshURIs()
RefreshURIFromQueue();
// Resume refresh URIs for our child shells as well.
PRInt32 n = mChildList.Count();
PRUint32 n = mChildList.Length();
for (PRInt32 i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(ChildAt(i));
for (PRUint32 i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> shell = do_QueryInterface(mChildList[i]);
if (shell)
shell->ResumeRefreshURIs();
}
@ -6371,9 +6371,9 @@ nsDocShell::CaptureState()
// Capture the docshell hierarchy.
mOSHE->ClearChildShells();
PRInt32 childCount = mChildList.Count();
for (PRInt32 i = 0; i < childCount; ++i) {
nsCOMPtr<nsIDocShellTreeItem> childShell = do_QueryInterface(ChildAt(i));
PRUint32 childCount = mChildList.Length();
for (PRUint32 i = 0; i < childCount; ++i) {
nsCOMPtr<nsIDocShellTreeItem> childShell = do_QueryInterface(mChildList[i]);
NS_ASSERTION(childShell, "null child shell");
mOSHE->AddChildShell(childShell);
@ -6440,9 +6440,9 @@ nsDocShell::BeginRestore(nsIContentViewer *aContentViewer, PRBool aTop)
nsresult
nsDocShell::BeginRestoreChildren()
{
PRInt32 n = mChildList.Count();
for (PRInt32 i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
PRUint32 n = mChildList.Length();
for (PRUint32 i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(mChildList[i]);
if (child) {
nsresult rv = child->BeginRestore(nsnull, PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
@ -6457,9 +6457,9 @@ nsDocShell::FinishRestore()
// First we call finishRestore() on our children. In the simulated load,
// all of the child frames finish loading before the main document.
PRInt32 n = mChildList.Count();
for (PRInt32 i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
PRUint32 n = mChildList.Length();
for (PRUint32 i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(mChildList[i]);
if (child) {
child->FinishRestore();
}
@ -6926,9 +6926,9 @@ nsDocShell::RestoreFromHistory()
// Meta-refresh timers have been restarted for this shell, but not
// for our children. Walk the child shells and restart their timers.
PRInt32 n = mChildList.Count();
PRInt32 n = mChildList.Length();
for (i = 0; i < n; ++i) {
nsCOMPtr<nsIDocShell> child = do_QueryInterface(ChildAt(i));
nsCOMPtr<nsIDocShell> child = do_QueryInterface(mChildList[i]);
if (child)
child->ResumeRefreshURIs();
}
@ -9350,10 +9350,10 @@ nsDocShell::WalkHistoryEntries(nsISHEntry *aRootEntry,
// Walk the children of aRootShell and see if one of them
// has srcChild as a SHEntry.
PRInt32 childCount = aRootShell->mChildList.Count();
for (PRInt32 j = 0; j < childCount; ++j) {
PRUint32 childCount = aRootShell->mChildList.Length();
for (PRUint32 j = 0; j < childCount; ++j) {
nsDocShell *child =
static_cast<nsDocShell*>(aRootShell->ChildAt(j));
static_cast<nsDocShell*>(aRootShell->mChildList[j]);
if (child->HasHistoryEntry(childEntry)) {
childShell = child;

View File

@ -40,7 +40,6 @@
#define nsIDOMClassInfo_h___
#include "nsIClassInfoImpl.h"
#include "nsVoidArray.h"
#include "nsDOMClassInfoID.h"
#include "nsIXPCScriptable.h"
#include "nsIServiceManager.h"

View File

@ -48,7 +48,6 @@
#include "nsIDOMStorageList.h"
#include "nsIDOMStorageItem.h"
#include "nsInterfaceHashtable.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsPIDOMStorage.h"
#include "nsIDOMToString.h"

View File

@ -76,27 +76,10 @@ nsresult
nsSelectionState::SaveSelection(nsISelection *aSel)
{
if (!aSel) return NS_ERROR_NULL_POINTER;
PRInt32 i,rangeCount, arrayCount = mArray.Length();
PRInt32 i,rangeCount;
aSel->GetRangeCount(&rangeCount);
// if we need more items in the array, new them
if (arrayCount<rangeCount)
{
PRInt32 count = rangeCount-arrayCount;
for (i=0; i<count; i++)
{
mArray.AppendElement();
}
}
// else if we have too many, delete them
else if (arrayCount>rangeCount)
{
for (i = arrayCount-1; i >= rangeCount; i--)
{
mArray.RemoveElementAt(i);
}
}
mArray.SetLength(rangeCount);
// now store the selection ranges
nsresult res = NS_OK;

View File

@ -40,7 +40,6 @@
#include "nsTransactionItem.h"
#include "nsTransactionStack.h"
#include "nsVoidArray.h"
#include "nsTransactionManager.h"
#include "nsTransactionList.h"
#include "nsAutoPtr.h"

View File

@ -75,7 +75,7 @@ protected:
protected:
nsHashtable mGroupsHash; // hash keyed on command group.
// Entries are nsVoidArrays of pointers to PRUnichar*
// Entries are nsTArrays of pointers to char*
// This could be made more space-efficient, maybe with atoms
};

View File

@ -177,9 +177,7 @@ nsJavaXPTCStub::Destroy()
if (!mMaster) {
// delete each child stub
for (PRInt32 i = 0; i < mChildren.Count(); i++) {
delete (nsJavaXPTCStub*) mChildren[i];
}
mChildren.Clear();
// Since we are destroying this stub, also remove the mapping.
// It is possible for mJavaStrongRef to be NULL here. That is why we
@ -379,9 +377,9 @@ nsJavaXPTCStub::FindStubSupportingIID(const nsID &iid)
if (SupportsIID(iid))
return this;
for (PRInt32 i = 0; i < mChildren.Count(); i++)
for (PRUint32 i = 0; i < mChildren.Length(); i++)
{
nsJavaXPTCStub *child = (nsJavaXPTCStub *) mChildren[i];
nsJavaXPTCStub *child = mChildren[i];
if (child->SupportsIID(iid))
return child;
}

View File

@ -40,7 +40,8 @@
#include "nsXPTCUtils.h"
#include "jni.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsAutoPtr.h"
#include "nsIInterfaceInfo.h"
#include "nsCOMPtr.h"
#include "nsWeakReference.h"
@ -138,7 +139,7 @@ private:
jint mJavaRefHashCode;
nsCOMPtr<nsIInterfaceInfo> mIInfo;
nsVoidArray mChildren; // weak references (cleared by the children)
nsTArray<nsAutoPtr<nsJavaXPTCStub> > mChildren; // weak references (cleared by the children)
nsJavaXPTCStub *mMaster; // strong reference
nsAutoRefCnt mWeakRefCnt; // count for number of associated weak refs

View File

@ -41,7 +41,6 @@
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIWindowWatcher.h"
#include "nsVoidArray.h"
#include "prmem.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeNode.h"

View File

@ -164,7 +164,7 @@ private:
nsSystemPrefService *mSysPrefService;
//listeners
nsAutoVoidArray *mObservers;
nsAutoTArray<nsAutoPtr<GConfCallbackData>, 8> mObservers;
void InitFuncPtrs();
//gconf public func ptrs
@ -205,27 +205,17 @@ private:
};
struct SysPrefCallbackData {
nsISupports *observer;
nsCOMPtr<nsISupports> observer;
PRBool bIsWeakRef;
PRUint32 prefAtom;
};
PRBool
sysPrefDeleteObserver(void *aElement, void *aData) {
SysPrefCallbackData *pElement =
static_cast<SysPrefCallbackData *>(aElement);
NS_RELEASE(pElement->observer);
nsMemory::Free(pElement);
return PR_TRUE;
}
NS_IMPL_ISUPPORTS2(nsSystemPrefService, nsIPrefBranch, nsIPrefBranch2)
/* public */
nsSystemPrefService::nsSystemPrefService()
:mInitialized(PR_FALSE),
mGConf(nsnull),
mObservers(nsnull)
mGConf(nsnull)
{
}
@ -235,10 +225,6 @@ nsSystemPrefService::~nsSystemPrefService()
if (mGConf)
delete mGConf;
if (mObservers) {
(void)mObservers->EnumerateForwards(sysPrefDeleteObserver, nsnull);
delete mObservers;
}
}
nsresult
@ -392,19 +378,10 @@ NS_IMETHODIMP nsSystemPrefService::AddObserver(const char *aDomain, nsIObserver
rv = mGConf->GetAtomForMozKey(aDomain, &prefAtom);
NS_ENSURE_SUCCESS(rv, rv);
if (!mObservers) {
mObservers = new nsAutoVoidArray();
if (mObservers == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
}
SysPrefCallbackData *cbData = new SysPrefCallbackData();
SysPrefCallbackData *pCallbackData = (SysPrefCallbackData *)
nsMemory::Alloc(sizeof(SysPrefCallbackData));
if (pCallbackData == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
pCallbackData->bIsWeakRef = aHoldWeak;
pCallbackData->prefAtom = prefAtom;
cbData->bIsWeakRef = aHoldWeak;
cbData->prefAtom = prefAtom;
// hold a weak reference to the observer if so requested
nsCOMPtr<nsISupports> observerRef;
if (aHoldWeak) {
@ -413,7 +390,7 @@ NS_IMETHODIMP nsSystemPrefService::AddObserver(const char *aDomain, nsIObserver
if (!weakRefFactory) {
// the caller didn't give us a object that supports weak reference.
// ... tell them
nsMemory::Free(pCallbackData);
delete cbData;
return NS_ERROR_INVALID_ARG;
}
nsCOMPtr<nsIWeakReference> tmp = do_GetWeakReference(weakRefFactory);
@ -422,16 +399,15 @@ NS_IMETHODIMP nsSystemPrefService::AddObserver(const char *aDomain, nsIObserver
observerRef = aObserver;
}
rv = mGConf->NotifyAdd(prefAtom, pCallbackData);
rv = mGConf->NotifyAdd(prefAtom, cbData);
if (NS_FAILED(rv)) {
nsMemory::Free(pCallbackData);
delete cbData;
return rv;
}
pCallbackData->observer = observerRef;
NS_ADDREF(pCallbackData->observer);
cbData->observer = observerRef;
mObservers.AppendElement(cbData);
mObservers->AppendElement(pCallbackData);
return NS_OK;
}
@ -443,9 +419,6 @@ NS_IMETHODIMP nsSystemPrefService::RemoveObserver(const char *aDomain, nsIObserv
NS_ENSURE_ARG_POINTER(aDomain);
NS_ENSURE_ARG_POINTER(aObserver);
NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE);
if (!mObservers)
return NS_OK;
PRUint32 prefAtom;
// make sure the pref name is supported
@ -453,38 +426,33 @@ NS_IMETHODIMP nsSystemPrefService::RemoveObserver(const char *aDomain, nsIObserv
NS_ENSURE_SUCCESS(rv, rv);
// need to find the index of observer, so we can remove it
PRIntn count = mObservers->Count();
if (count <= 0)
PRUint32 count = mObservers.Length();
if (!count)
return NS_OK;
PRIntn i;
SysPrefCallbackData *pCallbackData;
PRUint32 i;
for (i = 0; i < count; ++i) {
pCallbackData = (SysPrefCallbackData *)mObservers->ElementAt(i);
if (pCallbackData) {
nsCOMPtr<nsISupports> observerRef;
if (pCallbackData->bIsWeakRef) {
nsCOMPtr<nsISupportsWeakReference> weakRefFactory =
do_QueryInterface(aObserver);
if (weakRefFactory) {
nsCOMPtr<nsIWeakReference> tmp =
do_GetWeakReference(aObserver);
observerRef = tmp;
}
SysPrefCallbackData *cbData = mObservers[i];
nsCOMPtr<nsISupports> observerRef;
if (cbData->bIsWeakRef) {
nsCOMPtr<nsISupportsWeakReference> weakRefFactory =
do_QueryInterface(aObserver);
if (weakRefFactory) {
nsCOMPtr<nsIWeakReference> tmp =
do_GetWeakReference(aObserver);
observerRef = tmp;
}
if (!observerRef)
observerRef = aObserver;
}
if (!observerRef)
observerRef = aObserver;
if (pCallbackData->observer == observerRef &&
pCallbackData->prefAtom == prefAtom) {
rv = mGConf->NotifyRemove(prefAtom, pCallbackData);
if (NS_SUCCEEDED(rv)) {
mObservers->RemoveElementAt(i);
NS_RELEASE(pCallbackData->observer);
nsMemory::Free(pCallbackData);
}
return rv;
if (cbData->observer == observerRef &&
cbData->prefAtom == prefAtom) {
rv = mGConf->NotifyRemove(prefAtom, cbData);
if (NS_SUCCEEDED(rv)) {
mObservers.RemoveElementAt(i);
}
return rv;
}
}
return NS_OK;
@ -510,9 +478,7 @@ nsSystemPrefService::OnPrefChange(PRUint32 aPrefAtom, void *aData)
// this weak referenced observer went away, remove it from the list
nsresult rv = mGConf->NotifyRemove(aPrefAtom, pData);
if (NS_SUCCEEDED(rv)) {
mObservers->RemoveElement(pData);
NS_RELEASE(pData->observer);
nsMemory::Free(pData);
mObservers.RemoveElement(pData);
}
return;
}
@ -587,18 +553,12 @@ static const PrefNamePair sPrefNameMapping[] = {
{nsnull, nsnull},
};
PRBool
gconfDeleteObserver(void *aElement, void *aData) {
nsMemory::Free(aElement);
return PR_TRUE;
}
GConfProxy::GConfProxy(nsSystemPrefService *aSysPrefService):
mGConfClient(nsnull),
mGConfLib(nsnull),
mInitialized(PR_FALSE),
mSysPrefService(aSysPrefService),
mObservers(nsnull)
mSysPrefService(aSysPrefService)
{
}
@ -607,11 +567,6 @@ GConfProxy::~GConfProxy()
if (mGConfClient)
g_object_unref(G_OBJECT(mGConfClient));
if (mObservers) {
(void)mObservers->EnumerateForwards(gconfDeleteObserver, nsnull);
delete mObservers;
}
// bug 379666: can't unload GConf-2 since it registers atexit handlers
//PR_UnloadLibrary(mGConfLib);
}
@ -764,20 +719,13 @@ GConfProxy::NotifyAdd (PRUint32 aAtom, void *aUserData)
if (!gconfKey)
return NS_ERROR_FAILURE;
if (!mObservers) {
mObservers = new nsAutoVoidArray();
if (mObservers == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
}
GConfCallbackData *pData = (GConfCallbackData *)
nsMemory::Alloc(sizeof(GConfCallbackData));
GConfCallbackData *pData = new GConfCallbackData();
NS_ENSURE_TRUE(pData, NS_ERROR_OUT_OF_MEMORY);
pData->proxy = this;
pData->userData = aUserData;
pData->atom = aAtom;
mObservers->AppendElement(pData);
mObservers.AppendElement(pData);
GConfClientAddDir(mGConfClient, gconfKey,
0, // GCONF_CLIENT_PRELOAD_NONE, don't preload anything
@ -794,20 +742,18 @@ GConfProxy::NotifyRemove (PRUint32 aAtom, const void *aUserData)
{
NS_ENSURE_TRUE(mInitialized, NS_ERROR_FAILURE);
PRIntn count = mObservers->Count();
if (count <= 0)
PRUint32 count = mObservers.Length();
if (!count)
return NS_OK;
PRIntn i;
GConfCallbackData *pData;
PRUint32 i;
for (i = 0; i < count; ++i) {
pData = (GConfCallbackData *)mObservers->ElementAt(i);
if (pData && pData->atom == aAtom && pData->userData == aUserData) {
GConfCallbackData *pData = mObservers[i];
if (pData->atom == aAtom && pData->userData == aUserData) {
GConfClientNotifyRemove(mGConfClient, pData->notifyId);
GConfClientRemoveDir(mGConfClient,
GetGConfKey(pData->atom), NULL);
mObservers->RemoveElementAt(i);
nsMemory::Free(pData);
mObservers.RemoveElementAt(i);
break;
}
}

View File

@ -43,12 +43,14 @@
#define __SYSTEM_PREF_SERVICE_H__
#include "prlink.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsAutoPtr.h"
#include "nsWeakPtr.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
class GConfProxy;
struct SysPrefCallbackData;
////////////////////////////////////////////////////////////////////////////
// nsSystemPrefService provide a interface for read system prefs. It is
@ -74,7 +76,7 @@ private:
GConfProxy *mGConf;
//listeners
nsAutoVoidArray *mObservers;
nsAutoTArray<nsAutoPtr<SysPrefCallbackData>, 8> mObservers;
};
#define NS_SYSTEMPREF_SERVICE_CID \

View File

@ -40,7 +40,6 @@
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "mozIPersonalDictionary.h"
#include "nsIUnicodeEncoder.h"
#include "nsIObserver.h"

View File

@ -45,7 +45,6 @@
#include "mozIPersonalDictionary.h"
#include "mozISpellCheckingEngine.h"
#include "nsClassHashtable.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "mozISpellI18NUtil.h"

View File

@ -44,7 +44,6 @@
#include "nsLocale.h"
#include "nsLocaleCID.h"
#include "nsCOMPtr.h"
#include "nsVoidArray.h"
#include "nsMemory.h"
#include "nsCRT.h"

View File

@ -39,7 +39,6 @@
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsVoidArray.h"
#include "nsReadableUtils.h"
#include "nsIDOMDocumentStyle.h"
#include "nsIDOM3Node.h"

View File

@ -942,13 +942,12 @@ RuleProcessorData::~RuleProcessorData()
// Destroy potentially long chains of previous sibling and parent data
// without more than one level of recursion.
if (mPreviousSiblingData || mParentData) {
nsAutoVoidArray destroyQueue;
nsAutoTArray<RuleProcessorData*, 8> destroyQueue;
destroyQueue.AppendElement(this);
do {
RuleProcessorData *d = static_cast<RuleProcessorData*>
(destroyQueue.FastElementAt(destroyQueue.Count() - 1));
destroyQueue.RemoveElementAt(destroyQueue.Count() - 1);
RuleProcessorData *d = destroyQueue[destroyQueue.Length() - 1];
destroyQueue.RemoveElementAt(destroyQueue.Length() - 1);
if (d->mPreviousSiblingData) {
destroyQueue.AppendElement(d->mPreviousSiblingData);
@ -961,7 +960,7 @@ RuleProcessorData::~RuleProcessorData()
if (d != this)
d->Destroy();
} while (destroyQueue.Count());
} while (destroyQueue.Length());
}
delete mLanguage;

View File

@ -64,7 +64,7 @@
// Definitions
struct EnumerateData {
const char *parent;
nsVoidArray *pref_list;
nsTArray<const char*> *pref_list;
};
struct PrefCallbackData {
@ -562,11 +562,11 @@ NS_IMETHODIMP nsPrefBranch::DeleteBranch(const char *aStartingAt)
NS_IMETHODIMP nsPrefBranch::GetChildList(const char *aStartingAt, PRUint32 *aCount, char ***aChildArray)
{
char** outArray;
char* theElement;
PRInt32 numPrefs;
PRInt32 dwIndex;
const char* theElement;
PRUint32 numPrefs;
PRUint32 dwIndex;
EnumerateData ed;
nsAutoVoidArray prefArray;
nsAutoTArray<const char*, 8> prefArray;
NS_ENSURE_ARG_POINTER(aStartingAt);
NS_ENSURE_ARG_POINTER(aCount);
@ -587,7 +587,7 @@ NS_IMETHODIMP nsPrefBranch::GetChildList(const char *aStartingAt, PRUint32 *aCou
// now that we've built up the list, run the callback on
// all the matching elements
numPrefs = prefArray.Count();
numPrefs = prefArray.Length();
if (numPrefs) {
outArray = (char **)nsMemory::Alloc(numPrefs * sizeof(char *));
@ -597,7 +597,7 @@ NS_IMETHODIMP nsPrefBranch::GetChildList(const char *aStartingAt, PRUint32 *aCou
for (dwIndex = 0; dwIndex < numPrefs; ++dwIndex) {
// we need to lop off mPrefRoot in case the user is planning to pass this
// back to us because if they do we are going to add mPrefRoot again.
theElement = ((char *)prefArray.ElementAt(dwIndex)) + mPrefRootLength;
theElement = (prefArray.ElementAt(dwIndex)) + mPrefRootLength;
outArray[dwIndex] = (char *)nsMemory::Clone(theElement, strlen(theElement) + 1);
if (!outArray[dwIndex]) {
@ -629,7 +629,7 @@ NS_IMETHODIMP nsPrefBranch::AddObserver(const char *aDomain, nsIObserver *aObser
NS_ENSURE_ARG_POINTER(aObserver);
if (!mObservers) {
mObservers = new nsAutoVoidArray();
mObservers = new nsAutoTArray<PrefCallbackData*, 8>();
if (nsnull == mObservers)
return NS_ERROR_OUT_OF_MEMORY;
}
@ -669,8 +669,8 @@ NS_IMETHODIMP nsPrefBranch::RemoveObserver(const char *aDomain, nsIObserver *aOb
{
const char *pref;
PrefCallbackData *pCallback;
PRInt32 count;
PRInt32 i;
PRUint32 count;
PRUint32 i;
nsresult rv;
nsCAutoString domain;
@ -681,12 +681,12 @@ NS_IMETHODIMP nsPrefBranch::RemoveObserver(const char *aDomain, nsIObserver *aOb
return NS_OK;
// need to find the index of observer, so we can remove it from the domain list too
count = mObservers->Count();
count = mObservers->Length();
if (count == 0)
return NS_OK;
for (i = 0; i < count; i++) {
pCallback = (PrefCallbackData *)mObservers->ElementAt(i);
pCallback = mObservers->ElementAt(i);
if (pCallback) {
if (pCallback->pObserver == aObserver) {
domain = mObserverDomains[i];
@ -759,21 +759,21 @@ void nsPrefBranch::freeObserverList(void)
if (mObservers) {
// unregister the observers
PRInt32 count;
PRUint32 count;
count = mObservers->Count();
count = mObservers->Length();
if (count > 0) {
PRInt32 i;
PRUint32 i;
nsCAutoString domain;
for (i = 0; i < count; ++i) {
pCallback = (PrefCallbackData *)mObservers->ElementAt(i);
pCallback = mObservers->ElementAt(i);
if (pCallback) {
domain = mObserverDomains[i];
// We must pass a fully qualified preference name to remove the callback
pref = getPrefName(domain.get()); // can't fail because domain must be valid
// Remove this observer from our array so that nobody else can remove
// what we're trying to remove right now.
mObservers->ReplaceElementAt(nsnull, i);
mObservers->ElementAt(i) = nsnull;
PREF_UnregisterCallback(pref, NotifyObserver, pCallback);
if (pCallback->pWeakRef) {
NS_RELEASE(pCallback->pWeakRef);
@ -788,7 +788,7 @@ void nsPrefBranch::freeObserverList(void)
mObserverDomains.Clear();
}
delete mObservers;
mObservers = 0;
mObservers = nsnull;
}
}
@ -872,7 +872,7 @@ pref_enumChild(PLDHashTable *table, PLDHashEntryHdr *heh,
PrefHashEntry *he = static_cast<PrefHashEntry*>(heh);
EnumerateData *d = reinterpret_cast<EnumerateData *>(arg);
if (PL_strncmp(he->key, d->parent, PL_strlen(d->parent)) == 0) {
d->pref_list->AppendElement((void*)he->key);
d->pref_list->AppendElement(he->key);
}
return PL_DHASH_NEXT;
}

View File

@ -49,10 +49,11 @@
#include "nsIRelativeFilePref.h"
#include "nsILocalFile.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsWeakReference.h"
struct PrefCallbackData;
class nsPrefBranch : public nsIPrefBranchInternal,
public nsISecurityPref,
public nsIObserver,
@ -81,7 +82,7 @@ protected:
private:
PRInt32 mPrefRootLength;
nsAutoVoidArray *mObservers;
nsAutoTArray<PrefCallbackData*, 8> *mObservers;
nsCString mPrefRoot;
nsTArray<nsCString> mObserverDomains;
PRBool mIsDefault;

View File

@ -66,7 +66,6 @@
#include "nsAppDirectoryServiceDefs.h"
#include "nsThreadUtils.h"
#include "nsProxyRelease.h"
#include "nsVoidArray.h"
#include "nsDeleteDir.h"
#include "nsIPrivateBrowsingService.h"
#include "nsNetCID.h"

View File

@ -53,7 +53,6 @@ extern "C" {
}
#include "nsProxiedService.h"
#include "nsKeygenHandler.h"
#include "nsVoidArray.h"
#include "nsIServiceManager.h"
#include "nsIDOMHTMLSelectElement.h"
#include "nsIContent.h"

View File

@ -41,7 +41,6 @@
#define _NSKEYGENHANDLER_H_
// Form Processor
#include "nsIFormProcessor.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
nsresult GetSlotWithMechanism(PRUint32 mechanism,

View File

@ -40,7 +40,7 @@
#include <stdio.h>
#include "plhash.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsQuickSort.h"
/*
@ -57,10 +57,10 @@ struct AllocationNode {
// Other |AllocationNode| objects whose memory has a pointer to
// this object.
nsAutoVoidArray pointers_to;
nsAutoTArray<AllocationNode*, 8> pointers_to;
// The reverse.
nsAutoVoidArray pointers_from;
nsAutoTArray<AllocationNode*, 8> pointers_from;
// Early on in the algorithm, the pre-order index from a DFS.
// Later on, set to the index of the strongly connected component to
@ -195,7 +195,7 @@ int main(int argc, char **argv)
// |pointers_to|) and assign the post-order index to |index|.
{
PRUint32 dfs_index = 0;
nsVoidArray stack;
nsAutoTArray<AllocationNode*, 8> stack;
for (AllocationNode *n = nodes, *n_end = nodes+count; n != n_end; ++n) {
if (n->reached) {
@ -204,9 +204,8 @@ int main(int argc, char **argv)
stack.AppendElement(n);
do {
PRUint32 pos = stack.Count() - 1;
AllocationNode *n =
static_cast<AllocationNode*>(stack[pos]);
PRUint32 pos = stack.Length() - 1;
AllocationNode *n = stack[pos];
if (n->reached) {
n->index = dfs_index++;
stack.RemoveElementAt(pos);
@ -215,14 +214,14 @@ int main(int argc, char **argv)
// When doing post-order processing, we have to be
// careful not to put reached nodes into the stack.
nsVoidArray &pt = n->pointers_to;
for (PRInt32 i = pt.Count() - 1; i >= 0; --i) {
if (!static_cast<AllocationNode*>(pt[i])->reached) {
nsAutoTArray<AllocationNode*, 8> &pt = n->pointers_to;
for (PRInt32 i = pt.Length() - 1; i >= 0; --i) {
if (!pt[i]->reached) {
stack.AppendElement(pt[i]);
}
}
}
} while (stack.Count() > 0);
} while (stack.Length() > 0);
}
}
@ -248,7 +247,7 @@ int main(int argc, char **argv)
for (size_t i = 0; i < count; ++i) {
nodes[i].reached = PR_FALSE;
}
nsVoidArray stack;
nsAutoTArray<AllocationNode*, 8> stack;
for (AllocationNode **sn = sorted_nodes,
**sn_end = sorted_nodes + count; sn != sn_end; ++sn) {
if ((*sn)->reached) {
@ -258,9 +257,8 @@ int main(int argc, char **argv)
// We found a new strongly connected index.
stack.AppendElement(*sn);
do {
PRUint32 pos = stack.Count() - 1;
AllocationNode *n =
static_cast<AllocationNode*>(stack[pos]);
PRUint32 pos = stack.Length() - 1;
AllocationNode *n = stack[pos];
stack.RemoveElementAt(pos);
if (!n->reached) {
@ -268,7 +266,7 @@ int main(int argc, char **argv)
n->index = num_sccs;
stack.AppendElements(n->pointers_from);
}
} while (stack.Count() > 0);
} while (stack.Length() > 0);
++num_sccs;
}
}
@ -281,7 +279,7 @@ int main(int argc, char **argv)
nodes[i].is_root = PR_TRUE;
}
nsVoidArray stack;
nsAutoTArray<AllocationNode*, 8> stack;
for (AllocationNode *n = nodes, *n_end = nodes+count; n != n_end; ++n) {
if (!n->is_root) {
continue;
@ -289,18 +287,16 @@ int main(int argc, char **argv)
// Loop through pointers_to, and add any that are in a
// different SCC to stack:
for (int i = n->pointers_to.Count() - 1; i >= 0; --i) {
AllocationNode *target =
static_cast<AllocationNode*>(n->pointers_to[i]);
for (int i = n->pointers_to.Length() - 1; i >= 0; --i) {
AllocationNode *target = n->pointers_to[i];
if (n->index != target->index) {
stack.AppendElement(target);
}
}
while (stack.Count() > 0) {
PRUint32 pos = stack.Count() - 1;
AllocationNode *n =
static_cast<AllocationNode*>(stack[pos]);
while (stack.Length() > 0) {
PRUint32 pos = stack.Length() - 1;
AllocationNode *n = stack[pos];
stack.RemoveElementAt(pos);
if (n->is_root) {
@ -398,12 +394,11 @@ int main(int argc, char **argv)
}
}
if (n->pointers_from.Count()) {
if (n->pointers_from.Length()) {
printf("\nPointers from:\n");
for (PRUint32 i = 0, i_end = n->pointers_from.Count();
for (PRUint32 i = 0, i_end = n->pointers_from.Length();
i != i_end; ++i) {
AllocationNode *t = static_cast<AllocationNode*>
(n->pointers_from[i]);
AllocationNode *t = n->pointers_from[i];
const ADLog::Entry *te = t->entry;
printf(" <a href=\"#o%d\">%s</a> (Object %d, ",
t - nodes, te->type, t - nodes);

View File

@ -117,25 +117,8 @@ RequestInfoHashInitEntry(PLDHashTable *table, PLDHashEntryHdr *entry,
return PR_TRUE;
}
struct nsListenerInfo {
nsListenerInfo(nsIWeakReference *aListener, unsigned long aNotifyMask)
: mWeakListener(aListener),
mNotifyMask(aNotifyMask)
{
}
// Weak pointer for the nsIWebProgressListener...
nsWeakPtr mWeakListener;
// Mask indicating which notifications the listener wants to receive.
unsigned long mNotifyMask;
};
nsDocLoader::nsDocLoader()
: mParent(nsnull),
mListenerInfoList(8),
mIsLoadingDocument(PR_FALSE),
mIsRestoringDocument(PR_FALSE),
mIsFlushingLayout(PR_FALSE)
@ -293,16 +276,16 @@ NS_IMETHODIMP
nsDocLoader::Stop(void)
{
nsresult rv = NS_OK;
PRInt32 count, i;
PRUint32 count, i;
PR_LOG(gDocLoaderLog, PR_LOG_DEBUG,
("DocLoader:%p: Stop() called\n", this));
count = mChildList.Count();
count = mChildList.Length();
nsCOMPtr<nsIDocumentLoader> loader;
for (i=0; i < count; i++) {
loader = ChildAt(i);
loader = mChildList[i];
if (loader) {
(void) loader->Stop();
@ -369,12 +352,12 @@ nsDocLoader::IsBusy()
}
/* check its child document loaders... */
PRInt32 count, i;
PRUint32 count, i;
count = mChildList.Count();
count = mChildList.Length();
for (i=0; i < count; i++) {
nsIDocumentLoader* loader = ChildAt(i);
nsIDocumentLoader* loader = mChildList[i];
// This is a safe cast, because we only put nsDocLoader objects into the
// array
@ -421,15 +404,6 @@ nsDocLoader::Destroy()
// Release all the information about network requests...
ClearRequestInfoHash();
// Release all the information about registered listeners...
PRInt32 count = mListenerInfoList.Count();
for(PRInt32 i = 0; i < count; i++) {
nsListenerInfo *info =
static_cast<nsListenerInfo*>(mListenerInfoList.ElementAt(i));
delete info;
}
mListenerInfoList.Clear();
mListenerInfoList.Compact();
@ -444,15 +418,15 @@ nsDocLoader::Destroy()
void
nsDocLoader::DestroyChildren()
{
PRInt32 i, count;
PRUint32 i, count;
count = mChildList.Count();
count = mChildList.Length();
// if the doc loader still has children...we need to enumerate the
// children and make them null out their back ptr to the parent doc
// loader
for (i=0; i < count; i++)
{
nsIDocumentLoader* loader = ChildAt(i);
nsIDocumentLoader* loader = mChildList[i];
if (loader) {
// This is a safe cast, as we only put nsDocLoader objects into the
@ -912,12 +886,8 @@ nsDocLoader::AddProgressListener(nsIWebProgressListener *aListener,
return NS_ERROR_INVALID_ARG;
}
info = new nsListenerInfo(listener, aNotifyMask);
if (!info) {
return NS_ERROR_OUT_OF_MEMORY;
}
rv = mListenerInfoList.AppendElement(info) ? NS_OK : NS_ERROR_FAILURE;
rv = mListenerInfoList.AppendElement(nsListenerInfo(listener, aNotifyMask)) ?
NS_OK : NS_ERROR_OUT_OF_MEMORY;
return rv;
}
@ -928,8 +898,8 @@ nsDocLoader::RemoveProgressListener(nsIWebProgressListener *aListener)
nsListenerInfo* info = GetListenerInfo(aListener);
if (info) {
rv = mListenerInfoList.RemoveElement(info) ? NS_OK : NS_ERROR_FAILURE;
delete info;
mListenerInfoList.RemoveElementAt(info - mListenerInfoList.Elements());
rv = NS_OK;
} else {
// The listener is not registered!
rv = NS_ERROR_FAILURE;
@ -955,12 +925,12 @@ PRInt64 nsDocLoader::GetMaxTotalProgress()
{
nsInt64 newMaxTotal = 0;
PRInt32 count = mChildList.Count();
PRUint32 count = mChildList.Length();
nsCOMPtr<nsIWebProgress> webProgress;
for (PRInt32 i=0; i < count; i++)
for (PRUint32 i=0; i < count; i++)
{
nsInt64 individualProgress = 0;
nsIDocumentLoader* docloader = ChildAt(i);
nsIDocumentLoader* docloader = mChildList[i];
if (docloader)
{
// Cast is safe since all children are nsDocLoader too
@ -1155,28 +1125,20 @@ void nsDocLoader::FireOnProgressChange(nsDocLoader *aLoadInitiator,
this, buffer.get(), aProgress, aProgressMax, aTotalProgress, aMaxTotalProgress));
#endif /* DEBUG */
/*
* First notify any listeners of the new progress info...
*
* Operate the elements from back to front so that if items get
* get removed from the list it won't affect our iteration
*/
// First notify any listeners of the new progress info...
nsCOMPtr<nsIWebProgressListener> listener;
PRInt32 count = mListenerInfoList.Count();
nsAutoTObserverArray<nsListenerInfo, 8>::EndLimitedIterator iter(mListenerInfoList);
while (--count >= 0) {
nsListenerInfo *info;
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_PROGRESS)) {
while (iter.HasMore()) {
nsListenerInfo &info = iter.GetNext();
if (!(info.mNotifyMask & nsIWebProgress::NOTIFY_PROGRESS)) {
continue;
}
listener = do_QueryReferent(info->mWeakListener);
listener = do_QueryReferent(info.mWeakListener);
if (!listener) {
// the listener went away. gracefully pull it out of the list.
mListenerInfoList.RemoveElementAt(count);
delete info;
mListenerInfoList.RemoveElementAt(&info - mListenerInfoList.Elements());
continue;
}
@ -1185,7 +1147,6 @@ void nsDocLoader::FireOnProgressChange(nsDocLoader *aLoadInitiator,
PRInt32(aProgress), PRInt32(aProgressMax),
PRInt32(aTotalProgress), PRInt32(aMaxTotalProgress));
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1231,34 +1192,25 @@ void nsDocLoader::FireOnStateChange(nsIWebProgress *aProgress,
NS_ASSERTION(aRequest, "Firing OnStateChange(...) notification with a NULL request!");
/*
* First notify any listeners of the new state info...
*
* Operate the elements from back to front so that if items get
* get removed from the list it won't affect our iteration
*/
// First notify any listeners of the new state info...
nsCOMPtr<nsIWebProgressListener> listener;
PRInt32 count = mListenerInfoList.Count();
nsAutoTObserverArray<nsListenerInfo, 8>::EndLimitedIterator iter(mListenerInfoList);
while (--count >= 0) {
nsListenerInfo *info;
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
if (!info || !(info->mNotifyMask & (aStateFlags >>16))) {
while (iter.HasMore()) {
nsListenerInfo &info = iter.GetNext();
if (!(info.mNotifyMask & (aStateFlags >>16))) {
continue;
}
listener = do_QueryReferent(info->mWeakListener);
listener = do_QueryReferent(info.mWeakListener);
if (!listener) {
// the listener went away. gracefully pull it out of the list.
mListenerInfoList.RemoveElementAt(count);
delete info;
mListenerInfoList.RemoveElementAt(&info - mListenerInfoList.Elements());
continue;
}
listener->OnStateChange(aProgress, aRequest, aStateFlags, aStatus);
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1274,34 +1226,25 @@ nsDocLoader::FireOnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI *aUri)
{
/*
* First notify any listeners of the new state info...
*
* Operate the elements from back to front so that if items get
* get removed from the list it won't affect our iteration
*/
// First notify any listeners of the new state info...
nsCOMPtr<nsIWebProgressListener> listener;
PRInt32 count = mListenerInfoList.Count();
nsAutoTObserverArray<nsListenerInfo, 8>::EndLimitedIterator iter(mListenerInfoList);
while (--count >= 0) {
nsListenerInfo *info;
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_LOCATION)) {
while (iter.HasMore()) {
nsListenerInfo &info = iter.GetNext();
if (!(info.mNotifyMask & nsIWebProgress::NOTIFY_LOCATION)) {
continue;
}
listener = do_QueryReferent(info->mWeakListener);
listener = do_QueryReferent(info.mWeakListener);
if (!listener) {
// the listener went away. gracefully pull it out of the list.
mListenerInfoList.RemoveElementAt(count);
delete info;
mListenerInfoList.RemoveElementAt(&info - mListenerInfoList.Elements());
continue;
}
listener->OnLocationChange(aWebProgress, aRequest, aUri);
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1316,35 +1259,27 @@ nsDocLoader::FireOnStatusChange(nsIWebProgress* aWebProgress,
nsresult aStatus,
const PRUnichar* aMessage)
{
/*
* First notify any listeners of the new state info...
*
* Operate the elements from back to front so that if items get
* get removed from the list it won't affect our iteration
*/
// First notify any listeners of the new state info...
nsCOMPtr<nsIWebProgressListener> listener;
PRInt32 count = mListenerInfoList.Count();
nsAutoTObserverArray<nsListenerInfo, 8>::EndLimitedIterator iter(mListenerInfoList);
while (--count >= 0) {
nsListenerInfo *info;
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_STATUS)) {
while (iter.HasMore()) {
nsListenerInfo &info = iter.GetNext();
if (!(info.mNotifyMask & nsIWebProgress::NOTIFY_STATUS)) {
continue;
}
listener = do_QueryReferent(info->mWeakListener);
listener = do_QueryReferent(info.mWeakListener);
if (!listener) {
// the listener went away. gracefully pull it out of the list.
mListenerInfoList.RemoveElementAt(count);
delete info;
mListenerInfoList.RemoveElementAt(&info - mListenerInfoList.Elements());
continue;
}
listener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
if (mParent) {
mParent->FireOnStatusChange(aWebProgress, aRequest, aStatus, aMessage);
@ -1362,32 +1297,26 @@ nsDocLoader::RefreshAttempted(nsIWebProgress* aWebProgress,
* false if the refresh should be blocked.
*
* First notify any listeners of the refresh attempt...
*
* Iterate the elements from back to front so that if items
* get removed from the list it won't affect our iteration
*/
PRBool allowRefresh = PR_TRUE;
PRInt32 count = mListenerInfoList.Count();
nsAutoTObserverArray<nsListenerInfo, 8>::EndLimitedIterator iter(mListenerInfoList);
while (--count >= 0) {
nsListenerInfo *info;
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_REFRESH)) {
while (iter.HasMore()) {
nsListenerInfo &info = iter.GetNext();
if (!(info.mNotifyMask & nsIWebProgress::NOTIFY_REFRESH)) {
continue;
}
nsCOMPtr<nsIWebProgressListener> listener =
do_QueryReferent(info->mWeakListener);
do_QueryReferent(info.mWeakListener);
if (!listener) {
// the listener went away. gracefully pull it out of the list.
mListenerInfoList.RemoveElementAt(count);
delete info;
mListenerInfoList.RemoveElementAt(&info - mListenerInfoList.Elements());
continue;
}
nsCOMPtr<nsIWebProgressListener2> listener2 =
do_QueryReferent(info->mWeakListener);
do_QueryReferent(info.mWeakListener);
if (!listener2)
continue;
@ -1399,7 +1328,6 @@ nsDocLoader::RefreshAttempted(nsIWebProgress* aWebProgress,
allowRefresh = allowRefresh && listenerAllowedRefresh;
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1411,23 +1339,19 @@ nsDocLoader::RefreshAttempted(nsIWebProgress* aWebProgress,
return allowRefresh;
}
nsListenerInfo *
nsDocLoader::nsListenerInfo *
nsDocLoader::GetListenerInfo(nsIWebProgressListener *aListener)
{
PRInt32 i, count;
PRUint32 i, count;
nsListenerInfo *info;
nsCOMPtr<nsISupports> listener1 = do_QueryInterface(aListener);
count = mListenerInfoList.Count();
count = mListenerInfoList.Length();
for (i=0; i<count; i++) {
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(i));
NS_ASSERTION(info, "There should NEVER be a null listener in the list");
if (info) {
nsCOMPtr<nsISupports> listener2 = do_QueryReferent(info->mWeakListener);
if (listener1 == listener2)
return info;
}
info = mListenerInfoList.Elements() + i;
nsCOMPtr<nsISupports> listener2 = do_QueryReferent(info->mWeakListener);
if (listener1 == listener2)
return info;
}
return nsnull;
}
@ -1554,34 +1478,25 @@ NS_IMETHODIMP nsDocLoader::OnSecurityChange(nsISupports * aContext,
nsCOMPtr<nsIRequest> request = do_QueryInterface(aContext);
nsIWebProgress* webProgress = static_cast<nsIWebProgress*>(this);
/*
* First notify any listeners of the new state info...
*
* Operate the elements from back to front so that if items get
* get removed from the list it won't affect our iteration
*/
// First notify any listeners of the new state info...
nsCOMPtr<nsIWebProgressListener> listener;
PRInt32 count = mListenerInfoList.Count();
nsAutoTObserverArray<nsListenerInfo, 8>::EndLimitedIterator iter(mListenerInfoList);
while (--count >= 0) {
nsListenerInfo *info;
info = static_cast<nsListenerInfo*>(mListenerInfoList.SafeElementAt(count));
if (!info || !(info->mNotifyMask & nsIWebProgress::NOTIFY_SECURITY)) {
while (iter.HasMore()) {
nsListenerInfo &info = iter.GetNext();
if (!(info.mNotifyMask & nsIWebProgress::NOTIFY_SECURITY)) {
continue;
}
listener = do_QueryReferent(info->mWeakListener);
listener = do_QueryReferent(info.mWeakListener);
if (!listener) {
// the listener went away. gracefully pull it out of the list.
mListenerInfoList.RemoveElementAt(count);
delete info;
mListenerInfoList.RemoveElementAt(&info - mListenerInfoList.Elements());
continue;
}
listener->OnSecurityChange(webProgress, request, aState);
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1619,11 +1534,11 @@ NS_IMETHODIMP nsDocLoader::SetPriority(PRInt32 aPriority)
if (p)
p->SetPriority(aPriority);
PRInt32 count = mChildList.Count();
PRUint32 count = mChildList.Length();
nsDocLoader *loader;
for (PRInt32 i=0; i < count; i++) {
loader = static_cast<nsDocLoader*>(ChildAt(i));
for (PRUint32 i=0; i < count; i++) {
loader = static_cast<nsDocLoader*>(mChildList[i]);
if (loader) {
loader->SetPriority(aPriority);
}
@ -1641,11 +1556,11 @@ NS_IMETHODIMP nsDocLoader::AdjustPriority(PRInt32 aDelta)
if (p)
p->AdjustPriority(aDelta);
PRInt32 count = mChildList.Count();
PRUint32 count = mChildList.Length();
nsDocLoader *loader;
for (PRInt32 i=0; i < count; i++) {
loader = static_cast<nsDocLoader*>(ChildAt(i));
for (PRUint32 i=0; i < count; i++) {
loader = static_cast<nsDocLoader*>(mChildList[i]);
if (loader) {
loader->AdjustPriority(aDelta);
}

View File

@ -48,7 +48,8 @@
#include "nsWeakReference.h"
#include "nsILoadGroup.h"
#include "nsCOMArray.h"
#include "nsVoidArray.h"
#include "nsTPtrArray.h"
#include "nsTObserverArray.h"
#include "nsString.h"
#include "nsIChannel.h"
#include "nsIProgressEventSink.h"
@ -62,7 +63,6 @@
#include "pldhash.h"
struct nsRequestInfo;
struct nsListenerInfo;
/****************************************************************************
* nsDocLoader implementation...
@ -128,6 +128,20 @@ public:
nsresult AddChildLoader(nsDocLoader* aChild);
nsDocLoader* GetParent() const { return mParent; }
struct nsListenerInfo {
nsListenerInfo(nsIWeakReference *aListener, unsigned long aNotifyMask)
: mWeakListener(aListener),
mNotifyMask(aNotifyMask)
{
}
// Weak pointer for the nsIWebProgressListener...
nsWeakPtr mWeakListener;
// Mask indicating which notifications the listener wants to receive.
unsigned long mNotifyMask;
};
protected:
virtual ~nsDocLoader();
@ -138,14 +152,6 @@ protected:
void Destroy();
virtual void DestroyChildren();
nsIDocumentLoader* ChildAt(PRInt32 i) {
return static_cast<nsDocLoader*>(mChildList[i]);
}
nsIDocumentLoader* SafeChildAt(PRInt32 i) {
return static_cast<nsDocLoader*>(mChildList.SafeElementAt(i));
}
void FireOnProgressChange(nsDocLoader* aLoadInitiator,
nsIRequest *request,
PRInt64 aProgress,
@ -216,11 +222,11 @@ protected:
nsDocLoader* mParent; // [WEAK]
nsVoidArray mListenerInfoList;
nsAutoTObserverArray<nsListenerInfo, 8> mListenerInfoList;
nsCOMPtr<nsILoadGroup> mLoadGroup;
nsCOMPtr<nsILoadGroup> mLoadGroup;
// We hold weak refs to all our kids
nsVoidArray mChildList;
nsTPtrArray<nsIDocumentLoader> mChildList;
// The following member variables are related to the new nsIWebProgress
// feedback interfaces that travis cooked up.

View File

@ -148,11 +148,10 @@ nsViewManager::PostInvalidateEvent()
#undef DEBUG_MOUSE_LOCATION
PRInt32 nsViewManager::mVMCount = 0;
nsIRenderingContext* nsViewManager::gCleanupContext = nsnull;
// Weakly held references to all of the view managers
nsVoidArray* nsViewManager::gViewManagers = nsnull;
nsTArray<nsViewManager*>* nsViewManager::gViewManagers = nsnull;
PRUint32 nsViewManager::gLastUserEventTime = 0;
nsViewManager::nsViewManager()
@ -161,9 +160,8 @@ nsViewManager::nsViewManager()
, mRootViewManager(this)
{
if (gViewManagers == nsnull) {
NS_ASSERTION(mVMCount == 0, "View Manager count is incorrect");
// Create an array to hold a list of view managers
gViewManagers = new nsVoidArray;
gViewManagers = new nsTArray<nsViewManager*>;
}
if (gCleanupContext == nsnull) {
@ -175,7 +173,7 @@ nsViewManager::nsViewManager()
gViewManagers->AppendElement(this);
if (++mVMCount == 1) {
if (gViewManagers->Length() == 1) {
NS_AddFocusSuppressorCallback(&nsViewManager::SuppressFocusEvents);
}
// NOTE: we use a zeroing operator new, so all data members are
@ -205,16 +203,13 @@ nsViewManager::~nsViewManager()
mRootScrollable = nsnull;
NS_ASSERTION((mVMCount > 0), "underflow of viewmanagers");
--mVMCount;
#ifdef DEBUG
PRBool removed =
#endif
gViewManagers->RemoveElement(this);
NS_ASSERTION(removed, "Viewmanager instance not was not in the global list of viewmanagers");
NS_ASSERTION(removed, "Viewmanager instance was not in the global list of viewmanagers");
if (0 == mVMCount) {
if (gViewManagers->IsEmpty()) {
// There aren't any more view managers so
// release the global array of view managers
@ -2172,9 +2167,9 @@ nsViewManager::FlushPendingInvalidates()
mRefreshEnabled = PR_FALSE;
++mUpdateBatchCnt;
PRInt32 index;
for (index = 0; index < mVMCount; index++) {
nsViewManager* vm = (nsViewManager*)gViewManagers->ElementAt(index);
PRUint32 index;
for (index = 0; index < gViewManagers->Length(); index++) {
nsViewManager* vm = gViewManagers->ElementAt(index);
if (vm->RootViewManager() == this) {
// One of our kids
nsIViewObserver* observer = vm->GetViewObserver();

View File

@ -43,7 +43,7 @@
#include "nsITimer.h"
#include "prtime.h"
#include "prinrval.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"
#include "nsIScrollableView.h"
#include "nsIRegion.h"
@ -456,13 +456,12 @@ private:
PRPackedBool mInScroll;
//from here to public should be static and locked... MMP
static PRInt32 mVMCount; //number of viewmanagers
//Rendering context used to cleanup the blending buffers
static nsIRenderingContext* gCleanupContext;
//list of view managers
static nsVoidArray *gViewManagers;
static nsTArray<nsViewManager*> *gViewManagers;
void PostInvalidateEvent();

View File

@ -123,6 +123,20 @@ class nsAutoTObserverArray : protected nsTObserverArray_base {
return mArray.IsEmpty();
}
// This method provides direct access to the array elements.
// @return A pointer to the first element of the array. If the array is
// empty, then this pointer must not be dereferenced.
elem_type* Elements() {
return mArray.Elements();
}
// This method provides direct, readonly access to the array elements.
// @return A pointer to the first element of the array. If the array is
// empty, then this pointer must not be dereferenced.
const elem_type* Elements() const {
return mArray.Elements();
}
// This method provides direct access to the i'th element of the array.
// The given index must be within the array bounds.
// @param i The index of an element in the array.
@ -243,6 +257,11 @@ class nsAutoTObserverArray : protected nsTObserverArray_base {
ClearIterators();
}
// Compact the array to minimize the memory it uses
void Compact() {
mArray.Compact();
}
//
// Iterators
//

View File

@ -41,7 +41,7 @@
#define nsXPITriggerInfo_h
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsTArray.h"
#include "nsCOMPtr.h"
#include "nsISupportsUtils.h"
#include "nsILocalFile.h"
@ -113,14 +113,14 @@ class nsXPITriggerInfo
~nsXPITriggerInfo();
void Add( nsXPITriggerItem *aItem )
{ if ( aItem ) mItems.AppendElement( (void*)aItem ); }
{ if ( aItem ) mItems.AppendElement( aItem ); }
nsXPITriggerItem* Get( PRUint32 aIndex )
{ return (nsXPITriggerItem*)mItems.ElementAt(aIndex);}
{ return mItems.ElementAt(aIndex);}
void SaveCallback( JSContext *aCx, jsval aVal );
PRUint32 Size() { return mItems.Count(); }
PRUint32 Size() { return mItems.Length(); }
void SendStatus(const PRUnichar* URL, PRInt32 status);
@ -128,7 +128,7 @@ class nsXPITriggerInfo
private:
nsVoidArray mItems;
nsTArray<nsXPITriggerItem*> mItems;
JSContext *mCx;
nsCOMPtr<nsISupports> mContextWrapper;
jsval mCbval;