include/xmloff/fasttokenhandler.hxx               |   16 ++++++++++++++--
 include/xmloff/xmlimp.hxx                         |    7 +++++--
 sc/source/filter/xml/XMLTrackedChangesContext.cxx |    6 +++---
 xmloff/source/core/fasttokenhandler.cxx           |   11 ++++++++++-
 xmloff/source/core/xmlimp.cxx                     |   10 ++++------
 5 files changed, 36 insertions(+), 14 deletions(-)

New commits:
commit 885ae558d34dd76955c727b90eb9ae52ce85df7f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Oct 31 14:06:21 2019 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Oct 31 18:54:45 2019 +0100

    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.gran...@collabora.co.uk>

diff --git a/include/xmloff/fasttokenhandler.hxx 
b/include/xmloff/fasttokenhandler.hxx
index a95b3506a5f1..e134604eae70 100644
--- a/include/xmloff/fasttokenhandler.hxx
+++ b/include/xmloff/fasttokenhandler.hxx
@@ -32,10 +32,18 @@ public:
     {
         SAL_WARN_IF(nToken < 0 || nToken >= XML_TOKEN_COUNT, "xmloff", "Wrong 
nToken parameter");
         if( 0 <= nToken && nToken < XML_TOKEN_COUNT )
-            return maTokenNames[ nToken ];
+            return maTokenNamesUtf8[ nToken ];
         return EMPTY_BYTE_SEQ;
     }
 
+    const OUString& getTokenName( sal_Int32 nToken ) const
+    {
+        SAL_WARN_IF(nToken < 0 || nToken >= XML_TOKEN_COUNT, "xmloff", "Wrong 
nToken parameter");
+        if( 0 <= nToken && nToken < XML_TOKEN_COUNT )
+            return maTokenNames[ nToken ];
+        return EMPTY_STRING;
+    }
+
     /** Returns the token identifier for the passed UTF-8 token name. */
     static sal_Int32 getTokenFromUtf8( const css::uno::Sequence< sal_Int8 >& 
rUtf8Name )
     {
@@ -52,9 +60,11 @@ public:
 private:
     static sal_Int32 getTokenPerfectHash( const char *pToken, sal_Int32 
nLength );
 
-    std::vector< css::uno::Sequence< sal_Int8 > > maTokenNames;
+    std::vector< css::uno::Sequence< sal_Int8 > > maTokenNamesUtf8;
+    std::vector< OUString > maTokenNames;
 
     static const css::uno::Sequence< sal_Int8 > EMPTY_BYTE_SEQ;
+    static const OUString EMPTY_STRING;
 };
 
 struct StaticTokenMap : public rtl::Static< TokenMap, StaticTokenMap > {};
@@ -71,6 +81,8 @@ public:
     virtual css::uno::Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( 
sal_Int32 nToken ) override;
     virtual sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< 
sal_Int8 >& Identifier ) override;
 
+    const OUString & getIdentifier( sal_Int32 nToken ) const;
+
     // Much faster direct C++ shortcut to the method that matters
     virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) 
const override;
 
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 78bc26a7c234..0007f6dd5086 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -90,6 +90,9 @@ enum class SvXMLErrorFlags;
 namespace xmloff {
     class RDFaImportHelper;
 }
+namespace xmloff::token {
+    class FastTokenHandler;
+}
 
 enum class SvXMLImportFlags {
     NONE            = 0x0000,
@@ -219,7 +222,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public 
cppu::WeakImplHelper<
     rtl::Reference < comphelper::AttributeList > maAttrList;
     rtl::Reference < comphelper::AttributeList > maNamespaceAttrList;
     css::uno::Reference< css::xml::sax::XFastDocumentHandler > 
mxFastDocumentHandler;
-    static css::uno::Reference< css::xml::sax::XFastTokenHandler > 
xTokenHandler;
+    static rtl::Reference< xmloff::token::FastTokenHandler > xTokenHandler;
     static std::unordered_map< sal_Int32, std::pair< OUString, OUString > > 
aNamespaceMap;
     static std::unordered_map< OUString, OUString > aNamespaceURIPrefixMap;
     static bool bIsNSMapsInitialized;
@@ -377,7 +380,7 @@ public:
     // get import helper for events
     XMLEventImportHelper& GetEventImport();
 
-    static OUString getNameFromToken( sal_Int32 nToken );
+    static const OUString & getNameFromToken( sal_Int32 nToken );
     static OUString getNamespacePrefixFromToken(sal_Int32 nToken, const 
SvXMLNamespaceMap* pMap);
     static OUString getNamespaceURIFromToken( sal_Int32 nToken );
     static OUString getNamespacePrefixFromURI( const OUString& rURI );
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)
commit 09758c0e717a9ff31b004532906f902763300a93
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Oct 31 10:58:11 2019 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Oct 31 18:54:34 2019 +0100

    tdf#125688, better sizing for some OUStringBuffer
    
    Change-Id: Ib1f49a53bd5e799455b57abd8532e3e61e119abe
    Reviewed-on: https://gerrit.libreoffice.org/81840
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/filter/xml/XMLTrackedChangesContext.cxx 
b/sc/source/filter/xml/XMLTrackedChangesContext.cxx
index e6631332a18d..c8e652f4522b 100644
--- a/sc/source/filter/xml/XMLTrackedChangesContext.cxx
+++ b/sc/source/filter/xml/XMLTrackedChangesContext.cxx
@@ -42,9 +42,9 @@ using namespace xmloff::token;
 class ScXMLChangeInfoContext : public ScXMLImportContext
 {
     ScMyActionInfo                      aInfo;
-    OUStringBuffer               sAuthorBuffer;
-    OUStringBuffer               sDateTimeBuffer;
-    OUStringBuffer               sCommentBuffer;
+    OUStringBuffer                      sAuthorBuffer{32};
+    OUStringBuffer                      sDateTimeBuffer{32};
+    OUStringBuffer                      sCommentBuffer{64};
     ScXMLChangeTrackingImportHelper*    pChangeTrackingImportHelper;
     sal_uInt32                          nParagraphCount;
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to