diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-31 14:06:21 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-31 18:54:45 +0100 |
commit | 885ae558d34dd76955c727b90eb9ae52ce85df7f (patch) | |
tree | 3dfe7a3f9ba268b3ec1affff1795dc23018fe260 /xmloff | |
parent | 09758c0e717a9ff31b004532906f902763300a93 (diff) |
tdf#125688, cache token names as OUString
to avoid construction cost, shaves 2% off load time
Change-Id: I37a70a6e989f53d67911a6cb217d07e2db55cb44
Reviewed-on: https://gerrit.libreoffice.org/81841
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/fasttokenhandler.cxx | 11 | ||||
-rw-r--r-- | xmloff/source/core/xmlimp.cxx | 10 |
2 files changed, 14 insertions, 7 deletions
diff --git a/xmloff/source/core/fasttokenhandler.cxx b/xmloff/source/core/fasttokenhandler.cxx index 319bdce5f367..7e7673bfb791 100644 --- a/xmloff/source/core/fasttokenhandler.cxx +++ b/xmloff/source/core/fasttokenhandler.cxx @@ -33,8 +33,10 @@ namespace token { using namespace css; const css::uno::Sequence< sal_Int8 > TokenMap::EMPTY_BYTE_SEQ; +const OUString TokenMap::EMPTY_STRING; TokenMap::TokenMap() : + maTokenNamesUtf8( static_cast< size_t >( XML_TOKEN_COUNT ) ), maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT ) ) { static const sal_Char* sppcTokenNames[] = @@ -44,11 +46,13 @@ TokenMap::TokenMap() : }; const sal_Char* const* ppcTokenName = sppcTokenNames; - for( auto& rTokenName : maTokenNames ) + int i = 0; + for( auto& rTokenName : maTokenNamesUtf8 ) { OString aUtf8Token( *ppcTokenName ); rTokenName = uno::Sequence< sal_Int8 >( reinterpret_cast< const sal_Int8* >( aUtf8Token.getStr() ), aUtf8Token.getLength() ); + maTokenNames[i++] = OUString( aUtf8Token.getStr(), aUtf8Token.getLength(), RTL_TEXTENCODING_UTF8 ); ++ppcTokenName; } } @@ -78,6 +82,11 @@ uno::Sequence< sal_Int8 > FastTokenHandler::getUTF8Identifier( sal_Int32 nToken return mrTokenMap.getUtf8TokenName( nToken ); } +const OUString& FastTokenHandler::getIdentifier( sal_Int32 nToken ) const +{ + return mrTokenMap.getTokenName( nToken ); +} + sal_Int32 FastTokenHandler::getTokenFromUTF8( const uno::Sequence< sal_Int8 >& rIdentifier ) { return TokenMap::getTokenFromUtf8( rIdentifier ); diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index a956c316a49f..7fd0613130c9 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -82,7 +82,7 @@ using namespace ::com::sun::star::container; using namespace ::com::sun::star::document; using namespace ::xmloff::token; -css::uno::Reference< css::xml::sax::XFastTokenHandler > SvXMLImport::xTokenHandler( new FastTokenHandler() ); +rtl::Reference< FastTokenHandler > SvXMLImport::xTokenHandler( new FastTokenHandler() ); std::unordered_map< sal_Int32, std::pair< OUString, OUString > > SvXMLImport::aNamespaceMap; std::unordered_map< OUString, OUString > SvXMLImport::aNamespaceURIPrefixMap; const OUString SvXMLImport::aDefaultNamespace = OUString(""); @@ -406,7 +406,7 @@ SvXMLImport::SvXMLImport( InitCtor_(); mxParser = xml::sax::FastParser::create( xContext ); setNamespaceHandler( maNamespaceHandler.get() ); - setTokenHandler( xTokenHandler ); + setTokenHandler( xTokenHandler.get() ); if ( !bIsNSMapsInitialized ) { initializeNamespaceMaps(); @@ -2013,11 +2013,9 @@ bool SvXMLImport::embeddedFontAlreadyProcessed( const OUString& url ) return false; } -OUString SvXMLImport::getNameFromToken( sal_Int32 nToken ) +const OUString & SvXMLImport::getNameFromToken( sal_Int32 nToken ) { - uno::Sequence< sal_Int8 > aSeq = xTokenHandler->getUTF8Identifier( nToken & TOKEN_MASK ); - return OUString( reinterpret_cast< const char* >( - aSeq.getConstArray() ), aSeq.getLength(), RTL_TEXTENCODING_UTF8 ); + return xTokenHandler->getIdentifier( nToken & TOKEN_MASK ); } OUString SvXMLImport::getNamespacePrefixFromToken(sal_Int32 nToken, const SvXMLNamespaceMap* pMap) |