diff --git a/mozilla/modules/libreg/xpcom/nsRegistry.cpp b/mozilla/modules/libreg/xpcom/nsRegistry.cpp index 654b97a26c9..f43af9f4cd9 100644 --- a/mozilla/modules/libreg/xpcom/nsRegistry.cpp +++ b/mozilla/modules/libreg/xpcom/nsRegistry.cpp @@ -94,6 +94,8 @@ protected: #ifdef EXTRA_THREADSAFE PRLock *mregLock; // libreg isn't threadsafe. Use locks to synchronize. #endif + char *mCurRegFile; // these are to prevent open from opening the registry again + uint32 mCurRegID; }; // nsRegistry @@ -363,7 +365,7 @@ NS_IMPL_ISUPPORTS1( nsRegistryValue, nsIRegistryValue ) | NR_StartupRegistry. | ------------------------------------------------------------------------------*/ nsRegistry::nsRegistry() - : mReg( 0 ) { + : mReg(0), mCurRegFile(NULL), mCurRegID(0) { NS_INIT_REFCNT(); // Ensure libreg is started. @@ -387,6 +389,8 @@ nsRegistry::~nsRegistry() { if( mReg ) { Close(); } + if (mCurRegFile) + nsCRT::free(mCurRegFile); #ifdef EXTRA_THREADSAFE if (mregLock) { PR_DestroyLock(mregLock); @@ -406,12 +410,27 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { if( !regFile ) { return OpenDefault(); } + + if (mCurRegFile && !nsCRT::strcmp(regFile, mCurRegFile)) + { + // Already open + return NS_OK; + } + // Ensure existing registry is closed. Close(); // Open specified registry. PR_Lock(mregLock); err = NR_RegOpen((char*)regFile, &mReg ); PR_Unlock(mregLock); + + // Store filename to prevent further opening of registry + if (mCurRegFile) + nsCRT::free(mCurRegFile); + // No error checking. If this fails, we will close/open the + // registry again even if it is the same file. So what. + mCurRegFile = nsCRT::strdup(regFile); + // Convert the result. return regerr2nsresult( err ); } @@ -423,6 +442,12 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( uint32 regid ) { REGERR err = REGERR_OK; + if (mCurRegID == regid) + { + // Already opened. + return NS_OK; + } + // Ensure existing registry is closed. Close(); @@ -459,6 +484,10 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( uint32 regid ) { PR_Unlock(mregLock); // Cleanup delete registryLocation; + + // Store the registry that was opened for optimizing future opens. + mCurRegID = regid; + // Convert the result. return regerr2nsresult( err ); } @@ -489,6 +518,10 @@ NS_IMETHODIMP nsRegistry::Close() { err = NR_RegClose( mReg ); PR_Unlock(mregLock); mReg = 0; + if (mCurRegFile) + nsCRT::free(mCurRegFile); + mCurRegFile = NULL; + mCurRegID = 0; } return regerr2nsresult( err ); } diff --git a/mozilla/xpcom/components/nsIRegistry.h b/mozilla/xpcom/components/nsIRegistry.h index 4fadece1bc9..1a489672524 100644 --- a/mozilla/xpcom/components/nsIRegistry.h +++ b/mozilla/xpcom/components/nsIRegistry.h @@ -138,7 +138,7 @@ struct nsIRegistry : public nsISupports { --------------------------------------------------------------------------*/ typedef uint32 Key; - enum WellKnownKeys { Users = 1, Common = 2, CurrentUser = 3 }; + enum WellKnownKeys { None = 0, Users = 1, Common = 2, CurrentUser = 3 }; enum WellKnownRegistry { ApplicationComponentRegistry = 1 diff --git a/mozilla/xpcom/components/nsRegistry.cpp b/mozilla/xpcom/components/nsRegistry.cpp index 654b97a26c9..f43af9f4cd9 100644 --- a/mozilla/xpcom/components/nsRegistry.cpp +++ b/mozilla/xpcom/components/nsRegistry.cpp @@ -94,6 +94,8 @@ protected: #ifdef EXTRA_THREADSAFE PRLock *mregLock; // libreg isn't threadsafe. Use locks to synchronize. #endif + char *mCurRegFile; // these are to prevent open from opening the registry again + uint32 mCurRegID; }; // nsRegistry @@ -363,7 +365,7 @@ NS_IMPL_ISUPPORTS1( nsRegistryValue, nsIRegistryValue ) | NR_StartupRegistry. | ------------------------------------------------------------------------------*/ nsRegistry::nsRegistry() - : mReg( 0 ) { + : mReg(0), mCurRegFile(NULL), mCurRegID(0) { NS_INIT_REFCNT(); // Ensure libreg is started. @@ -387,6 +389,8 @@ nsRegistry::~nsRegistry() { if( mReg ) { Close(); } + if (mCurRegFile) + nsCRT::free(mCurRegFile); #ifdef EXTRA_THREADSAFE if (mregLock) { PR_DestroyLock(mregLock); @@ -406,12 +410,27 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { if( !regFile ) { return OpenDefault(); } + + if (mCurRegFile && !nsCRT::strcmp(regFile, mCurRegFile)) + { + // Already open + return NS_OK; + } + // Ensure existing registry is closed. Close(); // Open specified registry. PR_Lock(mregLock); err = NR_RegOpen((char*)regFile, &mReg ); PR_Unlock(mregLock); + + // Store filename to prevent further opening of registry + if (mCurRegFile) + nsCRT::free(mCurRegFile); + // No error checking. If this fails, we will close/open the + // registry again even if it is the same file. So what. + mCurRegFile = nsCRT::strdup(regFile); + // Convert the result. return regerr2nsresult( err ); } @@ -423,6 +442,12 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( uint32 regid ) { REGERR err = REGERR_OK; + if (mCurRegID == regid) + { + // Already opened. + return NS_OK; + } + // Ensure existing registry is closed. Close(); @@ -459,6 +484,10 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( uint32 regid ) { PR_Unlock(mregLock); // Cleanup delete registryLocation; + + // Store the registry that was opened for optimizing future opens. + mCurRegID = regid; + // Convert the result. return regerr2nsresult( err ); } @@ -489,6 +518,10 @@ NS_IMETHODIMP nsRegistry::Close() { err = NR_RegClose( mReg ); PR_Unlock(mregLock); mReg = 0; + if (mCurRegFile) + nsCRT::free(mCurRegFile); + mCurRegFile = NULL; + mCurRegID = 0; } return regerr2nsresult( err ); }