include/xmloff/nmspmap.hxx | 11 +++++------ xmloff/source/core/nmspmap.cxx | 33 +++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 20 deletions(-)
New commits: commit 787525a314de9c8178d0fedcd71ddbd08ec41a55 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu May 16 13:10:44 2019 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat May 18 15:10:52 2019 +0200 tdf#125254 Performance: A spreadsheet opens too slow, NameSpaceEntry NameSpaceEntry does not need to be a weak object, it is sufficient to be ref-counted. The empty string in SvXMLNamespaceMap can be statically allocated. Don't allocate a NameSpaceEntry in GetKeyByAttrName_ if we don't intend to cache it. Takes the load time from 39.5s to 38.5s. Change-Id: I4a9a1296af84c12d44e9b3ff354297f37d29f1e8 Reviewed-on: https://gerrit.libreoffice.org/72515 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/include/xmloff/nmspmap.hxx b/include/xmloff/nmspmap.hxx index 1eb0f8f15b95..9c4c57393200 100644 --- a/include/xmloff/nmspmap.hxx +++ b/include/xmloff/nmspmap.hxx @@ -30,7 +30,7 @@ #include <sal/types.h> #include <rtl/ustring.hxx> #include <rtl/ref.hxx> -#include <cppuhelper/weak.hxx> +#include <salhelper/simplereferenceobject.hxx> #include <limits.h> @@ -39,7 +39,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 : public cppu::OWeakObject +class NameSpaceEntry : public salhelper::SimpleReferenceObject { public: // sName refers to the full namespace name @@ -47,7 +47,7 @@ public: // sPrefix is the prefix used to declare a given item to be from a given namespace OUString sPrefix; // nKey is the unique identifier of a namespace - sal_uInt16 nKey; + sal_uInt16 nKey; }; typedef ::std::pair < sal_uInt16, OUString > QNamePair; @@ -65,12 +65,11 @@ struct QNamePairHash typedef std::unordered_map < QNamePair, OUString, QNamePairHash > QNameCache; typedef std::unordered_map < OUString, ::rtl::Reference <NameSpaceEntry > > NameSpaceHash; -typedef std::map < sal_uInt16, ::rtl::Reference < NameSpaceEntry > > NameSpaceMap; +typedef std::unordered_map < sal_uInt16, ::rtl::Reference < NameSpaceEntry > > NameSpaceMap; class XMLOFF_DLLPUBLIC SvXMLNamespaceMap { - const OUString sXMLNS; - const OUString sEmpty; + OUString sXMLNS; NameSpaceHash aNameHash; mutable NameSpaceHash aNameCache; diff --git a/xmloff/source/core/nmspmap.cxx b/xmloff/source/core/nmspmap.cxx index 248a36213ee4..669d0cc9f727 100644 --- a/xmloff/source/core/nmspmap.cxx +++ b/xmloff/source/core/nmspmap.cxx @@ -46,6 +46,8 @@ using namespace ::xmloff::token; * Martin 13/06/01 */ +static const OUString sEmpty; + SvXMLNamespaceMap::SvXMLNamespaceMap() : sXMLNS( GetXMLToken ( XML_XMLNS ) ) { @@ -302,47 +304,50 @@ sal_uInt16 SvXMLNamespaceMap::GetKeyByAttrName_( const OUString& rAttrName, } else { - rtl::Reference<NameSpaceEntry> xEntry(new NameSpaceEntry); + OUString sEntryPrefix, sEntryName; sal_Int32 nColonPos = rAttrName.indexOf( ':' ); if( -1 == nColonPos ) { // case: no ':' found -> default namespace - xEntry->sPrefix.clear(); - xEntry->sName = rAttrName; + sEntryName = rAttrName; } else { // normal case: ':' found -> get prefix/suffix - xEntry->sPrefix = rAttrName.copy( 0L, nColonPos ); - xEntry->sName = rAttrName.copy( nColonPos + 1 ); + sEntryPrefix = rAttrName.copy( 0L, nColonPos ); + sEntryName = rAttrName.copy( nColonPos + 1 ); } if( pPrefix ) - *pPrefix = xEntry->sPrefix; + *pPrefix = sEntryPrefix; if( pLocalName ) - *pLocalName = xEntry->sName; + *pLocalName = sEntryName; - NameSpaceHash::const_iterator aIter = aNameHash.find( xEntry->sPrefix ); + NameSpaceHash::const_iterator aIter = aNameHash.find( sEntryPrefix ); if ( aIter != aNameHash.end() ) { // found: retrieve namespace key - nKey = xEntry->nKey = (*aIter).second->nKey; + nKey = (*aIter).second->nKey; if ( pNamespace ) *pNamespace = (*aIter).second->sName; } - else if ( xEntry->sPrefix == sXMLNS ) + else if ( sEntryPrefix == sXMLNS ) // not found, but xmlns prefix: return xmlns 'namespace' - nKey = xEntry->nKey = XML_NAMESPACE_XMLNS; + nKey = XML_NAMESPACE_XMLNS; else if( nColonPos == -1 ) // not found, and no namespace: 'namespace' none - nKey = xEntry->nKey = XML_NAMESPACE_NONE; + nKey = XML_NAMESPACE_NONE; else - nKey = xEntry->nKey = XML_NAMESPACE_UNKNOWN; + nKey = XML_NAMESPACE_UNKNOWN; if (bCache) { - aNameCache.emplace(rAttrName, xEntry); + rtl::Reference<NameSpaceEntry> xEntry(new NameSpaceEntry); + xEntry->sPrefix = std::move(sEntryPrefix); + xEntry->sName = std::move(sEntryName); + xEntry->nKey = std::move(nKey); + aNameCache.emplace(rAttrName, std::move(xEntry)); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits