bug 108071 Eliminate 4000 calls to malloc by using copy getters of

registry. r=dveditz, sr=sfraser


git-svn-id: svn://10.0.0.236/trunk@108250 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dp%netscape.com
2001-11-16 02:38:23 +00:00
parent d443ae56e1
commit 5a69dc4d07
8 changed files with 255 additions and 40 deletions

View File

@@ -119,6 +119,47 @@ interface nsIRegistryValue : nsISupports
readonly attribute PRUint32 length;
};
[uuid(3A15FC88-7A61-4Ab4-8E58-31E95fAB3DA8)]
/**
* It sucks that nsIRegistry has to always allocate and return
* strings. nsIRegistryGetter adds in interfaces for non allocating getters
* to registry values.
*/
interface nsIRegistryGetter : nsISupports
{
/**
* Get a string value of attribute valname in widestring or utf8 format
*
* @return
* NS_OK on success.
* buf has the string value copied into it. length is NOT changed.
* NS_ERROR_REG_BUFFER_TOO_SMALL if not enough buffer space.
* length is updated to actual length in chars including
* terminating NULL and buf will be unchanged.
* NS_ERROR_FAILURE if an unknown error happened. state of buf and
* length undefined.
* various failure codes otherwise. buf and length wont be updated.
*/
void getStringUTF8IntoBuffer(in nsRegistryKey baseKey, in string path,
inout char buf, inout PRUint32 length);
/**
* Get a a byte array value of attribute valname
*
* @return
* NS_OK on success. buf has the string value copied into it.
* length is updated to actual number of bytes copied into buf.
* NS_ERROR_REG_BUFFER_TOO_SMALL if not enough buffer space.
* length is updated to actual length in PRUint8s including
* terminating NULL and buf will be unchanged.
* NS_ERROR_FAILURE if an unknown error happened. state of buf and
* length undefined.
* various other failure codes otherwise. buf and length wont be updated.
*/
void getBytesUTF8IntoBuffer(in nsRegistryKey baseKey, in string path,
inout PRUint8 buf, inout PRUint32 length);
};
%{ C++
#include "nsIRegistryUtils.h"
%}

View File

@@ -357,7 +357,7 @@ static void reginfo2Length( const REGINFO &in, PRUint32 &out ) {
| This code generates the implementation of the nsISupports member functions |
| for each class implemented in this file. |
------------------------------------------------------------------------------*/
NS_IMPL_THREADSAFE_ISUPPORTS1( nsRegistry, nsIRegistry )
NS_IMPL_THREADSAFE_ISUPPORTS2(nsRegistry, nsIRegistry, nsIRegistryGetter)
NS_IMPL_ISUPPORTS2( nsRegSubtreeEnumerator, nsIEnumerator,
nsIRegistryEnumerator)
NS_IMPL_ISUPPORTS1( nsRegistryNode, nsIRegistryNode )
@@ -733,7 +733,8 @@ NS_IMETHODIMP nsRegistry::GetStringUTF8( nsRegistryKey baseKey, const char *path
// Attempt to get string into our fixed buffer
PR_Lock(mregLock);
err = NR_RegGetEntryString( mReg,(RKEY)baseKey,(char*)path, regStr, sizeof regStr );
err = NR_RegGetEntryString( mReg,(RKEY)baseKey,(char*)path, regStr,
sizeof(regStr) );
PR_Unlock(mregLock);
if ( err == REGERR_OK )
@@ -783,6 +784,30 @@ NS_IMETHODIMP nsRegistry::GetStringUTF8( nsRegistryKey baseKey, const char *path
return rv;
}
NS_IMETHODIMP
nsRegistry::GetStringUTF8IntoBuffer( nsRegistryKey baseKey, const char *path,
char *buf, PRUint32 *length )
{
REGERR err = REGERR_OK;
// Attempt to get string into our fixed buffer
PR_Lock(mregLock);
err = NR_RegGetEntryString( mReg,(RKEY)baseKey,(char*)path, buf, *length );
PR_Unlock(mregLock);
// Convert status.
nsresult rv = regerr2nsresult( err );
if (rv == NS_ERROR_REG_BUFFER_TOO_SMALL) {
// fill length with the actual length
nsresult rv1 = GetValueLength( baseKey, path, length );
if(NS_FAILED(rv1))
return rv1;
}
return rv;
}
/*--------------------------- nsRegistry::SetString ----------------------------
| Simply sets the registry contents using NR_RegSetEntryString. |
------------------------------------------------------------------------------*/
@@ -884,6 +909,41 @@ NS_IMETHODIMP nsRegistry::GetBytesUTF8( nsRegistryKey baseKey, const char *path,
return rv;
}
NS_IMETHODIMP
nsRegistry::GetBytesUTF8IntoBuffer( nsRegistryKey baseKey, const char *path,
PRUint8 *buf, PRUint32* length )
{
REGERR err = REGERR_OK;
// Get info about the requested entry.
PRUint32 type;
nsresult rv = GetValueType( baseKey, path, &type );
// See if that worked.
if(NS_FAILED(rv))
return rv;
// Make sure we are dealing with bytes
if (type != Bytes)
return NS_ERROR_REG_BADTYPE;
// Attempt to get bytes into our fixed buffer
PR_Lock(mregLock);
err = NR_RegGetEntry( mReg,(RKEY)baseKey,NS_CONST_CAST(char*,path),
buf, (unsigned long *)length );
PR_Unlock(mregLock);
rv = regerr2nsresult(rv);
if (rv == NS_ERROR_REG_BUFFER_TOO_SMALL) {
// fill length with the actual length
nsresult rv1 = GetValueLength( baseKey, path, length );
if(NS_FAILED(rv1))
return rv1;
}
return rv;
}
/*---------------------------- nsRegistry::GetInt ------------------------------
| This function is just shorthand for fetching a 1-element PRInt32 array. We |
| implement it "manually" using NR_RegGetEntry |

View File

@@ -43,13 +43,16 @@
#include "nsIRegistry.h"
#include "NSReg.h"
struct nsRegistry : public nsIRegistry {
struct nsRegistry : public nsIRegistry, nsIRegistryGetter {
// This class implements the nsISupports interface functions.
NS_DECL_ISUPPORTS
// This class implements the nsIRegistry interface functions.
NS_DECL_NSIREGISTRY
// Fast registry getters
NS_DECL_NSIREGISTRYGETTER
// ctor/dtor
nsRegistry();
virtual ~nsRegistry();