diff options
author | Jörg Budischewski <jbu@openoffice.org> | 2002-10-23 14:27:51 +0000 |
---|---|---|
committer | Jörg Budischewski <jbu@openoffice.org> | 2002-10-23 14:27:51 +0000 |
commit | f0079260c4d731767e5ae8d5fcc2528b0460d2b5 (patch) | |
tree | 670443b33f463d16734651416e861fc8690c0f1f /registry | |
parent | 8596482126ae53495a8c968044d1c32e7c98af70 (diff) |
#104452# added optimistic link lookup, which results in better performance, when the underlying registry does not use links
Diffstat (limited to 'registry')
-rw-r--r-- | registry/source/keyimpl.cxx | 36 | ||||
-rw-r--r-- | registry/source/regimpl.cxx | 101 | ||||
-rw-r--r-- | registry/source/regimpl.hxx | 8 |
3 files changed, 123 insertions, 22 deletions
diff --git a/registry/source/keyimpl.cxx b/registry/source/keyimpl.cxx index f4d4184e5dba..b8d01c9eaec8 100644 --- a/registry/source/keyimpl.cxx +++ b/registry/source/keyimpl.cxx @@ -2,9 +2,9 @@ * * $RCSfile: keyimpl.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: jsc $ $Date: 2001-07-23 15:43:28 $ + * last change: $Author: jbu $ $Date: 2002-10-23 15:27:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -1205,24 +1205,30 @@ sal_uInt32 ORegKey::countSubKeys() // sal_Bool ORegKey::checkLink() { - RegValueType valueType = RG_VALUETYPE_NOT_DEFINED; - sal_uInt32 valueSize = 0; - OUString linkTarget( OUString( RTL_CONSTASCII_USTRINGPARAM("LINK_TARGET") )); - if (!((ORegKey*)this)->getValueInfo( linkTarget, &valueType, &valueSize)) + OUString aPath (m_name); aPath += m_pRegistry->ROOT; + OUString aName (RTL_CONSTASCII_USTRINGPARAM(VALUE_PREFIX "LINK_TARGET")); + + if (m_storeFile.attrib (aPath, aName, 0, 0) == store_E_None) { - sal_Unicode* value = (sal_Unicode*)rtl_allocateMemory(valueSize); - if (!((ORegKey*)this)->getValue( linkTarget, value)) - { - m_link = OUString(value); - m_isLink = sal_True; - } + OUString valueName (RTL_CONSTASCII_USTRINGPARAM("LINK_TARGET")); + RegValueType valueType = RG_VALUETYPE_NOT_DEFINED; + sal_uInt32 valueSize = 0; - rtl_freeMemory(value); + ORegKey* pThis = const_cast<ORegKey*>(this); + if (pThis->getValueInfo (valueName, &valueType, &valueSize) == REG_NO_ERROR) + { + sal_Unicode* value = (sal_Unicode*)rtl_allocateMemory(valueSize); + if (pThis->getValue (valueName, value) == REG_NO_ERROR) + { + m_link = OUString (value); + m_isLink = sal_True; + } - return sal_True; + rtl_freeMemory (value); + return sal_True; + } } - return sal_False; } diff --git a/registry/source/regimpl.cxx b/registry/source/regimpl.cxx index c81b18922802..37561e65f72a 100644 --- a/registry/source/regimpl.cxx +++ b/registry/source/regimpl.cxx @@ -2,9 +2,9 @@ * * $RCSfile: regimpl.cxx,v $ * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * - * last change: $Author: dbo $ $Date: 2002-07-30 12:00:48 $ + * last change: $Author: jbu $ $Date: 2002-10-23 15:27:47 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -678,6 +678,91 @@ RegError ORegistry::createKey(RegKeyHandle hKey, const OUString& keyName, //********************************************************************* // openKey // +static OUString makePath( const OUString & resolvedPath, const OUString &path ) +{ + OUStringBuffer buf(resolvedPath); + if( ! resolvedPath.getLength() || + '/' != resolvedPath[resolvedPath.getLength()-1]) + { + buf.appendAscii( "/" ); + } + + if( path[0] == '/' ) + { + buf.append( path.getStr()+1 ); + } + else + { + buf.append( path ); + } + return buf.makeStringAndClear(); +} + +RegError ORegistry::openKeyWithoutLink( + RegKeyHandle hKey, const OUString& keyName, + RegKeyHandle* phOpenKey) +{ + ORegKey* pKey; + ORegKey* pRet; + storeAccessMode accessMode = KEY_MODE_OPEN; + + *phOpenKey = NULL; + + if ( !keyName.getLength() ) + { + return REG_INVALID_KEYNAME; + } + + if ( isReadOnly() ) + { + accessMode = KEY_MODE_OPENREAD; + } + + REG_GUARD(m_mutex); + + if (hKey) + pKey = (ORegKey*)hKey; + else + pKey = m_openKeyTable[ROOT]; + + OUString sFullKeyName = makePath( pKey->getName(), keyName ); + OUString sFullPath; + OUString sRelativKey; + + sal_Int32 lastIndex = sFullKeyName.lastIndexOf('/'); + sRelativKey = sFullKeyName.copy(lastIndex + 1); + sFullPath = sFullKeyName.copy(0, lastIndex + 1); + + KeyMap::iterator ii = m_openKeyTable.find( sFullKeyName ); + if( ii == m_openKeyTable.end() ) + { + OStoreDirectory rStoreDir; + storeError _err = rStoreDir.create(pKey->getStoreFile(), sFullPath, sRelativKey, accessMode); + + if (_err == store_E_NotExists) + return REG_KEY_NOT_EXISTS; + else + if (_err == store_E_WrongFormat) + return REG_INVALID_KEY; + + if( _err != store_E_None ) + return REG_KEY_NOT_EXISTS; + + pRet = new ORegKey(sFullKeyName, rStoreDir, this); + *phOpenKey = pRet; + m_openKeyTable[sFullKeyName] = pRet; + } + else + { + // try to open it directly + pRet = ii->second; + OSL_ASSERT( pRet ); + *phOpenKey = pRet; + } + pRet->acquire(); + return REG_NO_ERROR; +} + RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName, RegKeyHandle* phOpenKey, RESOLVE eResolve) { @@ -711,6 +796,13 @@ RegError ORegistry::openKey(RegKeyHandle hKey, const OUString& keyName, { case RESOLVE_FULL: { + // try the optimistic approach (links aren't recognized) + RegKeyHandle handle = 0; + if( REG_NO_ERROR == openKeyWithoutLink( hKey, keyName,&handle ) ) + { + *phOpenKey = handle; + return REG_NO_ERROR; + } sFullKeyName = resolveLinks(pKey, keyName); if ( !sFullKeyName.getLength() ) @@ -2042,6 +2134,7 @@ RegError ORegistry::deleteLink(RegKeyHandle hKey, const OUString& linkName) //********************************************************************* // resolveLinks() // + OUString ORegistry::resolveLinks(ORegKey* pKey, const OUString& path, sal_Bool firstLinkOnly) { OUString resolvedPath(pKey->getName()); @@ -2049,9 +2142,6 @@ OUString ORegistry::resolveLinks(ORegKey* pKey, const OUString& path, sal_Bool f OUString token; ORegKey* pLink = NULL; -// if (resolvedPath.getLength() > 1) -// resolvedPath += ROOT; - if ( path.getStr()[0] == '/' ) nIndex++; @@ -2118,6 +2208,7 @@ ORegKey* ORegistry::resolveLink(ORegKey* pKey, OUString& resolvedPath, const OUS } else { resolvedPath += name; + return NULL; } } diff --git a/registry/source/regimpl.hxx b/registry/source/regimpl.hxx index 458766bafe17..fe17d299bb24 100644 --- a/registry/source/regimpl.hxx +++ b/registry/source/regimpl.hxx @@ -2,9 +2,9 @@ * * $RCSfile: regimpl.hxx,v $ * - * $Revision: 1.1.1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: hr $ $Date: 2000-09-18 15:18:42 $ + * last change: $Author: jbu $ $Date: 2002-10-23 15:27:49 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -242,6 +242,10 @@ protected: const OUString& sName, sal_Int16 nSpace) const; + RegError openKeyWithoutLink(RegKeyHandle hKey, + const OUString& keyName, + RegKeyHandle* phOpenKey); + OUString resolveLinks(ORegKey* pKey, const OUString& path, sal_Bool firstLinkOnly=sal_False); ORegKey* resolveLink(ORegKey* pKey, OUString& resolvedPath, const OUString& name); |