diff options
-rw-r--r-- | include/xmloff/namespacemap.hxx | 11 | ||||
-rw-r--r-- | sc/source/filter/xml/sheetdata.cxx | 8 | ||||
-rw-r--r-- | xmloff/source/core/namespacemap.cxx | 52 |
3 files changed, 34 insertions, 37 deletions
diff --git a/include/xmloff/namespacemap.hxx b/include/xmloff/namespacemap.hxx index 361ddfb7311d..81edfc52e25d 100644 --- a/include/xmloff/namespacemap.hxx +++ b/include/xmloff/namespacemap.hxx @@ -38,7 +38,7 @@ const sal_uInt16 XML_NAMESPACE_NONE = USHRT_MAX-1; const sal_uInt16 XML_NAMESPACE_UNKNOWN = USHRT_MAX; const sal_uInt16 XML_NAMESPACE_UNKNOWN_FLAG = 0x8000; -class NameSpaceEntry final : public salhelper::SimpleReferenceObject +class NameSpaceEntry final { public: // sName refers to the full namespace name @@ -47,6 +47,11 @@ public: OUString sPrefix; // nKey is the unique identifier of a namespace sal_uInt16 nKey; + + bool operator==(NameSpaceEntry const & rhs) const + { + return sName == rhs.sName && sPrefix == rhs.sPrefix && nKey == rhs.nKey; + } }; typedef ::std::pair < sal_uInt16, OUString > QNamePair; @@ -63,8 +68,8 @@ struct QNamePairHash }; typedef std::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache; -typedef std::unordered_map < OUString, ::rtl::Reference <NameSpaceEntry > > NameSpaceHash; -typedef std::unordered_map < sal_uInt16, ::rtl::Reference < NameSpaceEntry > > NameSpaceMap; +typedef std::unordered_map < OUString, NameSpaceEntry > NameSpaceHash; +typedef std::unordered_map < sal_uInt16, NameSpaceEntry > NameSpaceMap; class XMLOFF_DLLPUBLIC SvXMLNamespaceMap { diff --git a/sc/source/filter/xml/sheetdata.cxx b/sc/source/filter/xml/sheetdata.cxx index 7533a06a85a2..51ae5c3aaf97 100644 --- a/sc/source/filter/xml/sheetdata.cxx +++ b/sc/source/filter/xml/sheetdata.cxx @@ -186,12 +186,12 @@ void ScSheetSaveData::StoreLoadedNamespaces( const SvXMLNamespaceMap& rNamespace // store the loaded namespaces, so the prefixes in copied stream fragments remain valid const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries(); - for (const auto& [rName, rxEntry] : rNameHash) + for (const auto& [rName, rEntry] : rNameHash) { // ignore the initial namespaces if ( maInitialPrefixes.find( rName ) == maInitialPrefixes.end() ) { - maLoadedNamespaces.emplace_back( rxEntry->sPrefix, rxEntry->sName, rxEntry->nKey ); + maLoadedNamespaces.emplace_back( rEntry.sPrefix, rEntry.sName, rEntry.nKey ); } } } @@ -199,7 +199,7 @@ void ScSheetSaveData::StoreLoadedNamespaces( const SvXMLNamespaceMap& rNamespace static bool lcl_NameInHash( const NameSpaceHash& rNameHash, const OUString& rName ) { return std::any_of(rNameHash.begin(), rNameHash.end(), - [&rName](const NameSpaceHash::value_type& rEntry) { return rEntry.second->sName == rName; }); + [&rName](const NameSpaceHash::value_type& rEntry) { return rEntry.second.sName == rName; }); } bool ScSheetSaveData::AddLoadedNamespaces( SvXMLNamespaceMap& rNamespaces ) const @@ -214,7 +214,7 @@ bool ScSheetSaveData::AddLoadedNamespaces( SvXMLNamespaceMap& rNamespaces ) cons NameSpaceHash::const_iterator aHashIter = rNameHash.find( rLoadedNamespace.maPrefix ); // same prefix, but different name: loaded namespaces can't be used - bool bNameConflict = (aHashIter != rNameHash.end()) && (aHashIter->second->sName != rLoadedNamespace.maName); + bool bNameConflict = (aHashIter != rNameHash.end()) && (aHashIter->second.sName != rLoadedNamespace.maName); // a second prefix for the same name would confuse SvXMLNamespaceMap lookup, // so this is also considered a conflict 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<NameSpaceEntry> 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<NameSpaceEntry> 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, |