Remove double hash lookup.

Added extra add ref to cache
r=jband (submitted by him)
This commit is contained in:
dougt%netscape.com 2000-02-09 08:08:20 +00:00
parent 2f30889014
commit 359cd1e026
3 changed files with 26 additions and 8 deletions

View File

@ -37,7 +37,8 @@
#include "nsIInterfaceInfoManager.h"
#include "xptcall.h"
// LIFETIME_CACHE will cache class for the entire cyle of the application.
#define LIFETIME_CACHE
static uint32 zero_methods_descriptor;
@ -82,9 +83,9 @@ nsProxyEventClass::GetNewOrUsedClass(REFNSIID aIID)
nsCRT::free(iidStr);
#endif
if(iidToClassMap->Exists(&key))
{
clazz = (nsProxyEventClass*) iidToClassMap->Get(&key);
clazz = (nsProxyEventClass*) iidToClassMap->Get(&key);
if(clazz)
{
NS_ADDREF(clazz);
#ifdef PROXYEVENTCLASS_DEBUG
char* iidStr = aIID.ToString();
@ -160,6 +161,10 @@ nsProxyEventClass::nsProxyEventClass(REFNSIID aIID, nsIInterfaceInfo* aInfo)
if (iidToClassMap != nsnull)
{
iidToClassMap->Put(&key, this);
#ifdef LIFETIME_CACHE
// extra addref to hold it in the cache
NS_ADDREF_THIS();
#endif
#ifdef PROXYEVENTCLASS_DEBUG
char* iidStr = aIID.ToString();
printf("GetNewOrUsedClass %s put\n", iidStr);
@ -190,6 +195,7 @@ nsProxyEventClass::~nsProxyEventClass()
if(mDescriptors && mDescriptors != &zero_methods_descriptor)
delete [] mDescriptors;
#ifndef LIFETIME_CACHE
nsIDKey key(mIID);
nsProxyObjectManager *manager = nsProxyObjectManager::GetInstance();
@ -206,6 +212,7 @@ nsProxyEventClass::~nsProxyEventClass()
nsCRT::free(iidStr);
#endif
}
#endif
}
nsresult

View File

@ -171,10 +171,10 @@ nsProxyEventObject::GetNewOrUsedProxy(nsIEventQueue *destQueue,
// find in our hash table
if(realToProxyMap->Exists(&rootkey))
root = (nsProxyEventObject*) realToProxyMap->Get(&rootkey);
if(root)
{
root = (nsProxyEventObject*) realToProxyMap->Get(&rootkey);
proxy = root->Find(aIID);
proxy = root->Find(aIID);
if(proxy)
{

View File

@ -99,9 +99,20 @@ nsProxyObjectManager::nsProxyObjectManager()
mProxyObjectMap = new nsHashtable(256, PR_TRUE);
}
static PRBool PurgeProxyClasses(nsHashKey *aKey, void *aData, void* closure)
{
nsProxyEventClass* ptr = NS_REINTERPRET_CAST(nsProxyEventClass*, aData);
NS_RELEASE(ptr);
return PR_TRUE;
}
nsProxyObjectManager::~nsProxyObjectManager()
{
delete mProxyClassMap;
if (mProxyClassMap)
{
mProxyClassMap->Reset(PurgeProxyClasses, nsnull);
delete mProxyClassMap;
}
delete mProxyObjectMap;
nsProxyObjectManager::mInstance = nsnull;