From e8f2ccb42014b5eccabd42e5f95190be9e8f4519 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 24 May 2022 10:54:09 +0200 Subject: flatten the maps in SvXMLNamespaceMap to reduce pointer chasing Change-Id: I8d581c03f80fa279a93ed23b7116c6f950405b7a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134857 Tested-by: Jenkins Reviewed-by: Noel Grandin --- xmloff/source/core/namespacemap.cxx | 52 ++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 30 deletions(-) (limited to 'xmloff') diff --git a/xmloff/source/core/namespacemap.cxx b/xmloff/source/core/namespacemap.cxx index 3e28a4437cc2..4ef226e2a2f6 100644 --- a/xmloff/source/core/namespacemap.cxx +++ b/xmloff/source/core/namespacemap.cxx @@ -104,12 +104,8 @@ sal_uInt16 SvXMLNamespaceMap::Add_( const OUString& rPrefix, const OUString &rNa } while ( true ); } - ::rtl::Reference pEntry(new NameSpaceEntry); - pEntry->sName = rName; - pEntry->nKey = nKey; - pEntry->sPrefix = rPrefix; - aNameHash[ rPrefix ] = pEntry; - aNameMap [ nKey ] = pEntry; + aNameHash.insert_or_assign( rPrefix, NameSpaceEntry{ rName, rPrefix, nKey} ); + aNameMap.insert_or_assign( nKey, NameSpaceEntry{ rName, rPrefix, nKey} ); return nKey; } @@ -146,7 +142,7 @@ sal_uInt16 SvXMLNamespaceMap::AddIfKnown( const OUString& rPrefix, const OUStrin if( XML_NAMESPACE_UNKNOWN != nKey ) { NameSpaceHash::const_iterator aIter = aNameHash.find( rPrefix ); - if( aIter == aNameHash.end() || (*aIter).second->sName != rName ) + if( aIter == aNameHash.end() || (*aIter).second.sName != rName ) nKey = Add_( rPrefix, rName, nKey ); } @@ -157,17 +153,17 @@ sal_uInt16 SvXMLNamespaceMap::AddIfKnown( const OUString& rPrefix, const OUStrin sal_uInt16 SvXMLNamespaceMap::GetKeyByPrefix( const OUString& rPrefix ) const { NameSpaceHash::const_iterator aIter = aNameHash.find(rPrefix); - return (aIter != aNameHash.end()) ? (*aIter).second->nKey : USHRT_MAX; + return (aIter != aNameHash.end()) ? (*aIter).second.nKey : USHRT_MAX; } sal_uInt16 SvXMLNamespaceMap::GetKeyByName( const OUString& rName ) const { sal_uInt16 nKey = XML_NAMESPACE_UNKNOWN; auto aIter = std::find_if(aNameHash.cbegin(), aNameHash.cend(), - [&rName](const NameSpaceHash::value_type& rEntry) { return rEntry.second->sName == rName; }); + [&rName](const NameSpaceHash::value_type& rEntry) { return rEntry.second.sName == rName; }); if (aIter != aNameHash.cend()) - nKey = (*aIter).second->nKey; + nKey = (*aIter).second.nKey; return nKey; } @@ -175,13 +171,13 @@ sal_uInt16 SvXMLNamespaceMap::GetKeyByName( const OUString& rName ) const const OUString& SvXMLNamespaceMap::GetPrefixByKey( sal_uInt16 nKey ) const { NameSpaceMap::const_iterator aIter = aNameMap.find (nKey); - return (aIter != aNameMap.end()) ? (*aIter).second->sPrefix : sEmpty; + return (aIter != aNameMap.end()) ? (*aIter).second.sPrefix : sEmpty; } const OUString& SvXMLNamespaceMap::GetNameByKey( sal_uInt16 nKey ) const { NameSpaceMap::const_iterator aIter = aNameMap.find (nKey); - return (aIter != aNameMap.end()) ? (*aIter).second->sName : sEmpty; + return (aIter != aNameMap.end()) ? (*aIter).second.sName : sEmpty; } OUString SvXMLNamespaceMap::GetAttrNameByKey( sal_uInt16 nKey ) const @@ -190,7 +186,7 @@ OUString SvXMLNamespaceMap::GetAttrNameByKey( sal_uInt16 nKey ) const if (aIter == aNameMap.end()) return OUString(); - const OUString & prefix( (*aIter).second->sPrefix ); + const OUString & prefix( (*aIter).second.sPrefix ); if (prefix.isEmpty()) // default namespace return sXMLNS; @@ -245,7 +241,7 @@ OUString SvXMLNamespaceMap::GetQNameByKey( sal_uInt16 nKey, if ( aIter != aNameMap.end() ) { // ...if it's in our map, make the prefix - const OUString & prefix( (*aIter).second->sPrefix ); + const OUString & prefix( (*aIter).second.sPrefix ); OUStringBuffer sQName(prefix.getLength() + 1 + rLocalName.getLength()); if (!prefix.isEmpty()) // not default namespace { @@ -300,7 +296,7 @@ sal_uInt16 SvXMLNamespaceMap::GetKeyByQName(const OUString& rQName, it = aNameCache.end(); if ( it != aNameCache.end() ) { - const NameSpaceEntry &rEntry = *((*it).second); + const NameSpaceEntry &rEntry = (*it).second; if ( pPrefix ) *pPrefix = rEntry.sPrefix; if ( pLocalName ) @@ -309,7 +305,7 @@ sal_uInt16 SvXMLNamespaceMap::GetKeyByQName(const OUString& rQName, if ( pNamespace ) { NameSpaceMap::const_iterator aMapIter = aNameMap.find (nKey); - *pNamespace = aMapIter != aNameMap.end() ? (*aMapIter).second->sName : OUString(); + *pNamespace = aMapIter != aNameMap.end() ? (*aMapIter).second.sName : OUString(); } } else @@ -345,9 +341,9 @@ sal_uInt16 SvXMLNamespaceMap::GetKeyByQName(const OUString& rQName, if ( aIter != aNameHash.end() ) { // found: retrieve namespace key - nKey = (*aIter).second->nKey; + nKey = (*aIter).second.nKey; if ( pNamespace ) - *pNamespace = (*aIter).second->sName; + *pNamespace = (*aIter).second.sName; } else if ( sEntryPrefix == sXMLNS ) // not found, but xmlns prefix: return xmlns 'namespace' @@ -360,11 +356,7 @@ sal_uInt16 SvXMLNamespaceMap::GetKeyByQName(const OUString& rQName, if (eMode == QNameMode::AttrNameCached) { - rtl::Reference xEntry(new NameSpaceEntry); - xEntry->sPrefix = std::move(sEntryPrefix); - xEntry->sName = std::move(sEntryName); - xEntry->nKey = nKey; - aNameCache.emplace(rQName, std::move(xEntry)); + aNameCache.insert_or_assign(rQName, NameSpaceEntry{std::move(sEntryName), std::move(sEntryPrefix), nKey}); } } @@ -373,13 +365,13 @@ sal_uInt16 SvXMLNamespaceMap::GetKeyByQName(const OUString& rQName, sal_uInt16 SvXMLNamespaceMap::GetFirstKey() const { - return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second->nKey; + return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second.nKey; } sal_uInt16 SvXMLNamespaceMap::GetNextKey( sal_uInt16 nLastKey ) const { NameSpaceMap::const_iterator aIter = aNameMap.find ( nLastKey ); - return (++aIter == aNameMap.end()) ? USHRT_MAX : (*aIter).second->nKey; + return (++aIter == aNameMap.end()) ? USHRT_MAX : (*aIter).second.nKey; } @@ -391,13 +383,13 @@ sal_uInt16 SvXMLNamespaceMap::GetIndexByKey( sal_uInt16 nKey ) } sal_uInt16 SvXMLNamespaceMap::GetFirstIndex() const { - return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second->nKey; + return aNameMap.empty() ? USHRT_MAX : (*aNameMap.begin()).second.nKey; } sal_uInt16 SvXMLNamespaceMap::GetNextIndex( sal_uInt16 nOldIdx ) const { NameSpaceMap::const_iterator aIter = aNameMap.find ( nOldIdx ); - return (++aIter == aNameMap.end()) ? USHRT_MAX : (*aIter).second->nKey; + return (++aIter == aNameMap.end()) ? USHRT_MAX : (*aIter).second.nKey; } void SvXMLNamespaceMap::AddAtIndex( const OUString& rPrefix, @@ -421,19 +413,19 @@ OUString SvXMLNamespaceMap::GetAttrNameByIndex( sal_uInt16 nIdx ) const const OUString& SvXMLNamespaceMap::GetPrefixByIndex( sal_uInt16 nIdx ) const { NameSpaceMap::const_iterator aIter = aNameMap.find (nIdx); - return (aIter != aNameMap.end()) ? (*aIter).second->sPrefix : sEmpty; + return (aIter != aNameMap.end()) ? (*aIter).second.sPrefix : sEmpty; } const OUString& SvXMLNamespaceMap::GetNameByIndex( sal_uInt16 nIdx ) const { NameSpaceMap::const_iterator aIter = aNameMap.find (nIdx); - return (aIter != aNameMap.end()) ? (*aIter).second->sName : sEmpty; + return (aIter != aNameMap.end()) ? (*aIter).second.sName : sEmpty; } sal_uInt16 SvXMLNamespaceMap::GetIndexByPrefix( const OUString& rPrefix ) const { NameSpaceHash::const_iterator aIter = aNameHash.find(rPrefix); - return (aIter != aNameHash.end()) ? (*aIter).second->nKey : USHRT_MAX; + return (aIter != aNameHash.end()) ? (*aIter).second.nKey : USHRT_MAX; } sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName( const OUString& rAttrName, -- cgit