From 219c8267859c32d0c993bdf1e9258bf4d976339b Mon Sep 17 00:00:00 2001 From: "dougt%meer.net" Date: Fri, 23 May 2003 22:23:10 +0000 Subject: [PATCH] removing dynamically allocated hashtable in xpcom where possible. r=alecf, b=204634 git-svn-id: svn://10.0.0.236/trunk@142864 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/nsNativeComponentLoader.cpp | 43 ++++++------------- .../components/nsNativeComponentLoader.h | 4 +- mozilla/xpcom/components/xcDll.cpp | 9 +--- mozilla/xpcom/ds/nsObserverService.cpp | 1 - .../standalone/nsGREDirServiceProvider.cpp | 2 +- mozilla/xpcom/proxy/src/nsProxyEventPrivate.h | 8 ++-- .../xpcom/proxy/src/nsProxyObjectManager.cpp | 13 ++---- 7 files changed, 25 insertions(+), 55 deletions(-) diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.cpp b/mozilla/xpcom/components/nsNativeComponentLoader.cpp index e83ba862aaf..0cb944be7b5 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.cpp +++ b/mozilla/xpcom/components/nsNativeComponentLoader.cpp @@ -52,13 +52,6 @@ #include "prlog.h" extern PRLogModuleInfo *nsComponentManagerLog; -nsNativeComponentLoader::nsNativeComponentLoader() : - mCompMgr(nsnull), - mLoadedDependentLibs(nsnull), - mDllStore(nsnull) -{ -} - static PRBool PR_CALLBACK DLLStore_Destroy(nsHashKey *aKey, void *aData, void* closure) { @@ -67,11 +60,17 @@ DLLStore_Destroy(nsHashKey *aKey, void *aData, void* closure) return PR_TRUE; } +nsNativeComponentLoader::nsNativeComponentLoader() : + mCompMgr(nsnull), + mLoadedDependentLibs(16, PR_TRUE), + mDllStore(nsnull, nsnull, DLLStore_Destroy, + nsnull, 256, PR_TRUE) +{ +} + nsNativeComponentLoader::~nsNativeComponentLoader() { mCompMgr = nsnull; - delete mDllStore; - delete mLoadedDependentLibs; } NS_IMPL_THREADSAFE_ISUPPORTS2(nsNativeComponentLoader, @@ -158,20 +157,6 @@ nsNativeComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) if (!mCompMgr) return NS_ERROR_INVALID_ARG; - mDllStore = new nsObjectHashtable(nsnull, - nsnull, - DLLStore_Destroy, - nsnull, - 256, - PR_TRUE); - if (!mDllStore) - return NS_ERROR_OUT_OF_MEMORY; - - mLoadedDependentLibs = new nsHashtable(16, PR_TRUE); - - if (!mLoadedDependentLibs) - return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; } @@ -641,7 +626,7 @@ nsNativeComponentLoader::AutoUnregisterComponent(PRInt32 when, // Remove any autoreg info about this dll nsCStringKey key(persistentDescriptor); - mDllStore->RemoveAndDelete(&key); + mDllStore.RemoveAndDelete(&key); nsCOMPtr manager = do_QueryInterface(mCompMgr); NS_ASSERTION(manager, "Something is terribly wrong"); @@ -872,7 +857,7 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, dll = new nsDll(component, this); if (dll == NULL) return NS_ERROR_OUT_OF_MEMORY; - mDllStore->Put(&key, (void *) dll); + mDllStore.Put(&key, (void *) dll); } // dll == NULL // Either we are seeing the dll for the first time or the dll has @@ -973,9 +958,7 @@ nsNativeComponentLoader::UnloadAll(PRInt32 aWhen) callData.when = aWhen; // Cycle through the dlls checking to see if they want to be unloaded - if (mDllStore) { - mDllStore->Enumerate(nsFreeLibraryEnum, &callData); - } + mDllStore.Enumerate(nsFreeLibraryEnum, &callData); return NS_OK; } @@ -1008,7 +991,7 @@ nsNativeComponentLoader::CreateDll(nsIFile *aSpec, nsresult rv; nsCStringKey key(aLocation); - dll = (nsDll *)mDllStore->Get(&key); + dll = (nsDll *)mDllStore.Get(&key); if (dll) { *aDll = dll; @@ -1039,7 +1022,7 @@ nsNativeComponentLoader::CreateDll(nsIFile *aSpec, } *aDll = dll; - mDllStore->Put(&key, dll); + mDllStore.Put(&key, dll); return NS_OK; } diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.h b/mozilla/xpcom/components/nsNativeComponentLoader.h index b4d13ca2dcb..c33de4cbc99 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.h +++ b/mozilla/xpcom/components/nsNativeComponentLoader.h @@ -41,10 +41,10 @@ class nsNativeComponentLoader : public nsIComponentLoader, public nsINativeCompo virtual ~nsNativeComponentLoader(); nsIComponentManager* mCompMgr; // weak reference -- backpointer - nsHashtable* mLoadedDependentLibs; + nsHashtable mLoadedDependentLibs; private: - nsObjectHashtable* mDllStore; + nsObjectHashtable mDllStore; nsVoidArray mDeferredComponents; NS_IMETHOD RegisterComponentsInDir(PRInt32 when, nsIFile *dir); diff --git a/mozilla/xpcom/components/xcDll.cpp b/mozilla/xpcom/components/xcDll.cpp index 203ee259b63..0ab2ca3a5d0 100644 --- a/mozilla/xpcom/components/xcDll.cpp +++ b/mozilla/xpcom/components/xcDll.cpp @@ -144,11 +144,6 @@ PRBool nsDll::Load(void) // on the dependent libraries with the assumption that the // component library holds a reference via the OS so loader. - if (!m_loader->mLoadedDependentLibs) { - NS_ERROR("huh? no dependent libs"); - return PR_TRUE; - } - #if defined(XP_UNIX) nsCOMPtr manager = do_QueryInterface(m_loader->mCompMgr); if (!manager) @@ -188,12 +183,12 @@ PRBool nsDll::Load(void) while (token!=nsnull) { nsCStringKey key(token); - if (m_loader->mLoadedDependentLibs->Get(&key)) { + if (m_loader.mLoadedDependentLibs->Get(&key)) { token = nsCRT::strtok(newStr, " ", &newStr); continue; } - m_loader->mLoadedDependentLibs->Put(&key, (void*)1); + m_loader.mLoadedDependentLibs->Put(&key, (void*)1); nsXPIDLCString libpath; file->SetNativeLeafName(nsDependentCString(token)); diff --git a/mozilla/xpcom/ds/nsObserverService.cpp b/mozilla/xpcom/ds/nsObserverService.cpp index 114b1db3037..11246a1709b 100644 --- a/mozilla/xpcom/ds/nsObserverService.cpp +++ b/mozilla/xpcom/ds/nsObserverService.cpp @@ -74,7 +74,6 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsObserverService, nsIObserverService) nsObserverService::nsObserverService() : mObserverTopicTable(nsnull) { - mObserverTopicTable = nsnull; } nsObserverService::~nsObserverService(void) diff --git a/mozilla/xpcom/glue/standalone/nsGREDirServiceProvider.cpp b/mozilla/xpcom/glue/standalone/nsGREDirServiceProvider.cpp index 8394958b660..e58ba1d7bef 100644 --- a/mozilla/xpcom/glue/standalone/nsGREDirServiceProvider.cpp +++ b/mozilla/xpcom/glue/standalone/nsGREDirServiceProvider.cpp @@ -523,7 +523,7 @@ nsGREDirServiceProvider::AddGRELocationToPath() } if (mPathEnvString) - PR_Free(mPathEnvString); + PR_smprintf_free(mPathEnvString); mPathEnvString = PR_smprintf("%s=%s;%s", XPCOM_SEARCH_KEY, diff --git a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h index 390f2b36492..de993da4c00 100644 --- a/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h +++ b/mozilla/xpcom/proxy/src/nsProxyEventPrivate.h @@ -182,15 +182,15 @@ public: static void Shutdown(); - nsHashtable* GetRealObjectToProxyObjectMap() const { return mProxyObjectMap;} - nsHashtable* GetIIDToProxyClassMap() const { return mProxyClassMap; } + nsHashtable* GetRealObjectToProxyObjectMap() { return &mProxyObjectMap;} + nsHashtable* GetIIDToProxyClassMap() { return &mProxyClassMap; } PRMonitor* GetMonitor() const { return mProxyCreationMonitor; } private: static nsProxyObjectManager* mInstance; - nsHashtable *mProxyObjectMap; - nsHashtable *mProxyClassMap; + nsHashtable mProxyObjectMap; + nsHashtable mProxyClassMap; PRMonitor *mProxyCreationMonitor; }; diff --git a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp index af0f6deabc1..c0ba9700917 100644 --- a/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp +++ b/mozilla/xpcom/proxy/src/nsProxyObjectManager.cpp @@ -114,10 +114,9 @@ nsProxyObjectManager* nsProxyObjectManager::mInstance = nsnull; NS_IMPL_THREADSAFE_ISUPPORTS1(nsProxyObjectManager, nsIProxyObjectManager) nsProxyObjectManager::nsProxyObjectManager() +: mProxyClassMap(256, PR_TRUE), + mProxyObjectMap(256, PR_TRUE) { - mProxyClassMap = new nsHashtable(256, PR_TRUE); - mProxyObjectMap = new nsHashtable(256, PR_TRUE); - mProxyCreationMonitor = PR_NewMonitor(); } @@ -130,13 +129,7 @@ static PRBool PurgeProxyClasses(nsHashKey *aKey, void *aData, void* closure) nsProxyObjectManager::~nsProxyObjectManager() { - if (mProxyClassMap) - { - mProxyClassMap->Reset((nsHashtableEnumFunc)PurgeProxyClasses, nsnull); - delete mProxyClassMap; - } - - delete mProxyObjectMap; + mProxyClassMap.Reset((nsHashtableEnumFunc)PurgeProxyClasses, nsnull); if (mProxyCreationMonitor) { PR_DestroyMonitor(mProxyCreationMonitor);