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
Родитель 0f1fc4c7bf
Коммит 5621c81630
33 изменённых файлов: 317 добавлений и 470 удалений

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

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

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

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

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

@ -243,7 +243,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;
@ -251,7 +251,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;
@ -306,32 +306,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();
}

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

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

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

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

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

@ -783,9 +783,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) {
@ -1443,10 +1443,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();
@ -2098,9 +2098,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);
}
@ -2839,9 +2839,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
@ -2874,7 +2874,7 @@ NS_IMETHODIMP
nsDocShell::GetChildCount(PRInt32 * aChildCount)
{
NS_ENSURE_ARG_POINTER(aChildCount);
*aChildCount = mChildList.Count();
*aChildCount = mChildList.Length();
return NS_OK;
}
@ -2909,7 +2909,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
@ -2924,11 +2924,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;
}
@ -3048,12 +3048,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);
@ -3075,9 +3075,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);
@ -3975,10 +3975,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);
}
@ -5396,10 +5396,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();
}
@ -5413,10 +5413,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();
}
@ -6359,9 +6359,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);
@ -6428,9 +6428,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);
@ -6445,9 +6445,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();
}
@ -6914,9 +6914,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();
}
@ -9266,10 +9266,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;

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -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;
nsJavaXPTCStub *mMaster; // strong reference
nsAutoRefCnt mWeakRefCnt; // count for number of associated weak refs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -937,13 +937,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);
@ -956,7 +955,7 @@ RuleProcessorData::~RuleProcessorData()
if (d != this)
d->Destroy();
} while (destroyQueue.Count());
} while (destroyQueue.Length());
}
delete mLanguage;

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

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

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

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

1
netwerk/cache/src/nsCacheService.cpp поставляемый
Просмотреть файл

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

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

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

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

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

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

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

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

@ -117,25 +117,20 @@ 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;
// this is used for mListenerInfoList.Contains() and .RemoveElement()
NS_SPECIALIZE_TEMPLATE
class nsDefaultComparator <class nsDocLoader::nsListenerInfo, nsIWebProgressListener*> {
public:
PRBool Equals(const nsDocLoader::nsListenerInfo& aInfo,
nsIWebProgressListener* const& aListener) const {
nsCOMPtr<nsIWebProgressListener> listener =
do_QueryReferent(aInfo.mWeakListener);
return aListener == listener;
}
};
nsDocLoader::nsDocLoader()
: mParent(nsnull),
mListenerInfoList(8),
mIsLoadingDocument(PR_FALSE),
mIsRestoringDocument(PR_FALSE),
mIsFlushingLayout(PR_FALSE)
@ -293,16 +288,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 +364,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 +416,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 +430,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
@ -897,12 +883,9 @@ void nsDocLoader::doStopDocumentLoad(nsIRequest *request,
NS_IMETHODIMP
nsDocLoader::AddProgressListener(nsIWebProgressListener *aListener,
PRUint32 aNotifyMask)
PRUint32 aNotifyMask)
{
nsresult rv;
nsListenerInfo* info = GetListenerInfo(aListener);
if (info) {
if (mListenerInfoList.Contains(aListener)) {
// The listener is already registered!
return NS_ERROR_FAILURE;
}
@ -912,29 +895,14 @@ 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;
return rv;
return mListenerInfoList.AppendElement(nsListenerInfo(listener, aNotifyMask)) ?
NS_OK : NS_ERROR_OUT_OF_MEMORY;
}
NS_IMETHODIMP
nsDocLoader::RemoveProgressListener(nsIWebProgressListener *aListener)
{
nsresult rv;
nsListenerInfo* info = GetListenerInfo(aListener);
if (info) {
rv = mListenerInfoList.RemoveElement(info) ? NS_OK : NS_ERROR_FAILURE;
delete info;
} else {
// The listener is not registered!
rv = NS_ERROR_FAILURE;
}
return rv;
return mListenerInfoList.RemoveElement(aListener) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
@ -955,12 +923,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 +1123,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();
ListenerArray::BackwardIterator 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;
RemoveEmptyListeners();
continue;
}
@ -1185,7 +1145,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 +1190,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();
ListenerArray::BackwardIterator 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;
RemoveEmptyListeners();
continue;
}
listener->OnStateChange(aProgress, aRequest, aStateFlags, aStatus);
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1274,34 +1224,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();
ListenerArray::BackwardIterator 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;
RemoveEmptyListeners();
continue;
}
listener->OnLocationChange(aWebProgress, aRequest, aUri);
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1316,35 +1257,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();
ListenerArray::BackwardIterator 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;
RemoveEmptyListeners();
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 +1295,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();
ListenerArray::BackwardIterator 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;
RemoveEmptyListeners();
continue;
}
nsCOMPtr<nsIWebProgressListener2> listener2 =
do_QueryReferent(info->mWeakListener);
do_QueryReferent(info.mWeakListener);
if (!listener2)
continue;
@ -1399,7 +1326,6 @@ nsDocLoader::RefreshAttempted(nsIWebProgress* aWebProgress,
allowRefresh = allowRefresh && listenerAllowedRefresh;
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1411,27 +1337,6 @@ nsDocLoader::RefreshAttempted(nsIWebProgress* aWebProgress,
return allowRefresh;
}
nsListenerInfo *
nsDocLoader::GetListenerInfo(nsIWebProgressListener *aListener)
{
PRInt32 i, count;
nsListenerInfo *info;
nsCOMPtr<nsISupports> listener1 = do_QueryInterface(aListener);
count = mListenerInfoList.Count();
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;
}
}
return nsnull;
}
nsresult nsDocLoader::AddRequestInfo(nsIRequest *aRequest)
{
if (!PL_DHashTableOperate(&mRequestInfoHash, aRequest, PL_DHASH_ADD)) {
@ -1484,6 +1389,17 @@ void nsDocLoader::ClearRequestInfoHash(void)
PL_DHashTableEnumerate(&mRequestInfoHash, RemoveInfoCallback, nsnull);
}
/**
* RemoveElement() only finds the first Listener that resolves to null and
* may leave such empty Listeners behind at the end of the Array.
* This method makes sure it removes every one of those null-Listeners.
*/
void nsDocLoader::RemoveEmptyListeners()
{
while(mListenerInfoList.RemoveElement((nsIWebProgressListener*)nsnull)) {}
}
// PLDHashTable enumeration callback that calculates the max progress.
static PLDHashOperator
CalcMaxProgressCallback(PLDHashTable *table, PLDHashEntryHdr *hdr,
@ -1554,34 +1470,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();
ListenerArray::BackwardIterator 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;
RemoveEmptyListeners();
continue;
}
listener->OnSecurityChange(webProgress, request, aState);
}
mListenerInfoList.Compact();
// Pass the notification up to the parent...
@ -1619,11 +1526,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 +1548,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);
}

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

@ -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,12 @@ protected:
nsDocLoader* mParent; // [WEAK]
nsVoidArray mListenerInfoList;
typedef nsAutoTObserverArray<nsListenerInfo, 8> ListenerArray;
ListenerArray 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.
@ -263,14 +270,13 @@ private:
// aFlushLayout is true.
void DocLoaderIsEmpty(PRBool aFlushLayout);
nsListenerInfo *GetListenerInfo(nsIWebProgressListener* aListener);
PRInt64 GetMaxTotalProgress();
nsresult AddRequestInfo(nsIRequest* aRequest);
void RemoveRequestInfo(nsIRequest* aRequest);
nsRequestInfo *GetRequestInfo(nsIRequest* aRequest);
void ClearRequestInfoHash();
void RemoveEmptyListeners();
PRInt64 CalculateMaxProgress();
/// void DumpChannelInfo(void);

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

@ -142,11 +142,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()
@ -155,9 +154,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) {
@ -169,8 +167,6 @@ nsViewManager::nsViewManager()
gViewManagers->AppendElement(this);
++mVMCount;
// NOTE: we use a zeroing operator new, so all data members are
// assumed to be cleared here.
mHasPendingUpdates = PR_FALSE;
@ -198,16 +194,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
@ -2093,9 +2086,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();

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

@ -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"
@ -413,13 +413,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();

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

@ -185,7 +185,13 @@ class nsAutoTObserverArray : protected nsTObserverArray_base {
// @return PR_TRUE if the element was found, or inserted successfully.
template<class Item>
PRBool PrependElementUnlessExists(const Item& item) {
return Contains(item) || mArray.InsertElementAt(0, item) != nsnull;
if (Contains(item))
return PR_TRUE;
if (mArray.InsertElementAt(0, item) != nsnull) {
AdjustIterators(0, 1);
return PR_TRUE;
}
return PR_FALSE;
}
// Append an element to the array.
@ -243,6 +249,11 @@ class nsAutoTObserverArray : protected nsTObserverArray_base {
ClearIterators();
}
// Compact the array to minimize the memory it uses
void Compact() {
mArray.Compact();
}
//
// Iterators
//
@ -344,6 +355,38 @@ class nsAutoTObserverArray : protected nsTObserverArray_base {
ForwardIterator mEnd;
};
// Iterates the array backward from end to start. mPosition points
// to the element that was returned last.
// Elements:
// - prepended to the array during iteration *will* be traversed,
// unless the iteration already arrived at the first element
// - appended during iteration *will not* be traversed
// - removed during iteration *will not* be traversed.
class BackwardIterator : protected Iterator {
public:
typedef nsAutoTObserverArray<T, N> array_type;
typedef Iterator base_type;
BackwardIterator(const array_type& aArray)
: Iterator(aArray.Length(), aArray) {
}
// Returns PR_TRUE if there are more elements to iterate.
// This must precede a call to GetNext(). If PR_FALSE is
// returned, GetNext() must not be called.
PRBool HasMore() const {
return base_type::mPosition > 0;
}
// Returns the next element and steps one step. This must
// be preceded by a call to HasMore().
// @return The next observer.
elem_type& GetNext() {
NS_ASSERTION(HasMore(), "iterating beyond start of array");
return base_type::mArray.ElementAt(--base_type::mPosition);
}
};
protected:
nsAutoTArray<T, N> mArray;
};

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

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