[Libreoffice-commits] core.git: 2 commits - sax/source sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jul 20 06:59:08 UTC 2018


 sax/source/fastparser/fastparser.cxx |   63 ++++++++++++++++++++---------------
 sc/source/ui/dbgui/scuiimoptdlg.cxx  |   12 +++---
 sc/source/ui/inc/scuiimoptdlg.hxx    |    4 +-
 3 files changed, 44 insertions(+), 35 deletions(-)

New commits:
commit 8caf5129d46d1ebfdd66ebe4dd3d8463ad1aa035
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 19 12:05:57 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Jul 20 08:58:56 2018 +0200

    loplugin:useuniqueptr in ScImportOptionsDlg
    
    Change-Id: I7d3a7a72c5de2915822ebb4cc73a504e65ce04a6
    Reviewed-on: https://gerrit.libreoffice.org/57750
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/ui/dbgui/scuiimoptdlg.cxx b/sc/source/ui/dbgui/scuiimoptdlg.cxx
index b67b692de098..ab8371865a6b 100644
--- a/sc/source/ui/dbgui/scuiimoptdlg.cxx
+++ b/sc/source/ui/dbgui/scuiimoptdlg.cxx
@@ -139,8 +139,8 @@ ScImportOptionsDlg::ScImportOptionsDlg(
     sFieldSep = sFieldSep.replaceFirst( "%SPACE", ScResId(SCSTR_FIELDSEP_SPACE) );
 
     // not possible in the Ctor initializer (MSC cannot do that):
-    pFieldSepTab = new ScDelimiterTable(sFieldSep);
-    pTextSepTab  = new ScDelimiterTable(SCSTR_TEXTSEP);
+    pFieldSepTab.reset( new ScDelimiterTable(sFieldSep) );
+    pTextSepTab.reset( new ScDelimiterTable(SCSTR_TEXTSEP) );
 
     OUString aStr = pFieldSepTab->FirstDel();
     sal_Unicode nCode;
@@ -265,8 +265,8 @@ ScImportOptionsDlg::~ScImportOptionsDlg()
 
 void ScImportOptionsDlg::dispose()
 {
-    delete pFieldSepTab;
-    delete pTextSepTab;
+    pFieldSepTab.reset();
+    pTextSepTab.reset();
     m_pEncGrid.clear();
     m_pFieldFrame.clear();
     m_pFtCharset.clear();
@@ -305,9 +305,9 @@ sal_uInt16 ScImportOptionsDlg::GetCodeFromCombo( const ComboBox& rEd ) const
     sal_uInt16  nCode;
 
     if ( &rEd == m_pEdTextSep )
-        pTab = pTextSepTab;
+        pTab = pTextSepTab.get();
     else
-        pTab = pFieldSepTab;
+        pTab = pFieldSepTab.get();
 
     if ( aStr.isEmpty() )
     {
diff --git a/sc/source/ui/inc/scuiimoptdlg.hxx b/sc/source/ui/inc/scuiimoptdlg.hxx
index 7b0ec78987a1..fdc70bc026ab 100644
--- a/sc/source/ui/inc/scuiimoptdlg.hxx
+++ b/sc/source/ui/inc/scuiimoptdlg.hxx
@@ -59,8 +59,8 @@ private:
     VclPtr<OKButton>           m_pBtnOk;
 
 
-    ScDelimiterTable*   pFieldSepTab;
-    ScDelimiterTable*   pTextSepTab;
+    std::unique_ptr<ScDelimiterTable> pFieldSepTab;
+    std::unique_ptr<ScDelimiterTable> pTextSepTab;
 
     bool m_bIsAsciiImport;
 
commit c6acb048e6f40ead4110750a79eeb3d6d6d5865d
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 19 15:53:00 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Jul 20 08:58:45 2018 +0200

    tdf#79878 perf loading docx file, pendingChars
    
    Use std::vector<char> for pendingCharacters in SAXParser to avoid
    calling the OUString utf8 conversion routine more than one per character
    block. We seem to hit multiple characters() callbacks per chunk of text
    fairly often in loading writer docs.
    
    This is only good for about 0.5% performance
    
    Change-Id: I354bb4efe9d883c4bebf49bc96dd44be4f2b1610
    Reviewed-on: https://gerrit.libreoffice.org/57731
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 4ae2f4fdaf4a..3486dcd53759 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -273,7 +273,7 @@ private:
 
     Entity *mpTop;                          /// std::stack::top() is amazingly slow => cache this.
     std::stack< Entity > maEntities;        /// Entity stack for each call of parseStream().
-    OUString pendingCharacters;             /// Data from characters() callback that needs to be sent.
+    std::vector<char> pendingCharacters;    /// Data from characters() callback that needs to be sent.
 };
 
 } // namespace sax_fastparser
@@ -444,8 +444,7 @@ void Entity::startElement( Event const *pEvent )
                 xContext->startFastElement( nElementToken, xAttr );
         }
         // swap the reference we own in to avoid referencing thrash.
-        maContextStack.top().mxContext.set( xContext.get() );
-        xContext.set( nullptr, SAL_NO_ACQUIRE );
+        maContextStack.top().mxContext = std::move( xContext );
     }
     catch (...)
     {
@@ -461,10 +460,10 @@ void Entity::characters( const OUString& sChars )
         return;
     }
 
-    const Reference< XFastContextHandler >& xContext( maContextStack.top().mxContext );
-    if( xContext.is() ) try
+    XFastContextHandler * pContext( maContextStack.top().mxContext.get() );
+    if( pContext ) try
     {
-        xContext->characters( sChars );
+        pContext->characters( sChars );
     }
     catch (...)
     {
@@ -481,19 +480,20 @@ void Entity::endElement()
     }
 
     const SaxContext& aContext = maContextStack.top();
-    const Reference< XFastContextHandler >& xContext( aContext.mxContext );
-    if( xContext.is() ) try
-    {
-        sal_Int32 nElementToken = aContext.mnElementToken;
-        if( nElementToken != FastToken::DONTKNOW )
-            xContext->endFastElement( nElementToken );
-        else
-            xContext->endUnknownElement( aContext.maNamespace, aContext.maElementName );
-    }
-    catch (...)
-    {
-        saveException( ::cppu::getCaughtException() );
-    }
+    XFastContextHandler* pContext( aContext.mxContext.get() );
+    if( pContext )
+        try
+        {
+            sal_Int32 nElementToken = aContext.mnElementToken;
+            if( nElementToken != FastToken::DONTKNOW )
+                pContext->endFastElement( nElementToken );
+            else
+                pContext->endUnknownElement( aContext.maNamespace, aContext.maElementName );
+        }
+        catch (...)
+        {
+            saveException( ::cppu::getCaughtException() );
+        }
     maContextStack.pop();
 }
 
@@ -1083,7 +1083,7 @@ void FastSaxParserImpl::parse()
 void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xmlChar* prefix, const xmlChar* URI,
     int numNamespaces, const xmlChar** namespaces, int numAttributes, const xmlChar **attributes)
 {
-    if (!pendingCharacters.isEmpty())
+    if (!pendingCharacters.empty())
         sendPendingCharacters();
     Entity& rEntity = getEntity();
     if( rEntity.maNamespaceCount.empty() )
@@ -1254,7 +1254,7 @@ void FastSaxParserImpl::addUnknownElementWithPrefix(const xmlChar **attributes,
 
 void FastSaxParserImpl::callbackEndElement()
 {
-    if (!pendingCharacters.isEmpty())
+    if (!pendingCharacters.empty())
         sendPendingCharacters();
     Entity& rEntity = getEntity();
     SAL_WARN_IF(rEntity.maNamespaceCount.empty(), "sax", "Empty NamespaceCount");
@@ -1279,24 +1279,33 @@ void FastSaxParserImpl::callbackCharacters( const xmlChar* s, int nLen )
     // simpler FastSaxParser's character callback provides the whole string at once,
     // so merge data from possible multiple calls and send them at once (before the element
     // ends or another one starts).
-    pendingCharacters += OUString( XML_CAST( s ), nLen, RTL_TEXTENCODING_UTF8 );
+    //
+    // We use a std::vector<char> to avoid calling into the OUString constructor more than once when
+    // we have multiple callbackCharacters() calls that we have to merge, which happens surprisingly
+    // often in writer documents.
+    int nOriginalLen = pendingCharacters.size();
+    pendingCharacters.resize(nOriginalLen + nLen);
+    memcpy(pendingCharacters.data() + nOriginalLen, s, nLen);
 }
 
 void FastSaxParserImpl::sendPendingCharacters()
 {
     Entity& rEntity = getEntity();
-    Event& rEvent = rEntity.getEvent( CHARACTERS );
-    rEvent.msChars = pendingCharacters;
-    pendingCharacters.clear();
+    OUString sChars( pendingCharacters.data(), pendingCharacters.size(), RTL_TEXTENCODING_UTF8 );
     if (rEntity.mbEnableThreads)
+    {
+        Event& rEvent = rEntity.getEvent( CHARACTERS );
+        rEvent.msChars = sChars;
         produce();
+    }
     else
-        rEntity.characters( rEvent.msChars );
+        rEntity.characters( sChars );
+    pendingCharacters.resize(0);
 }
 
 void FastSaxParserImpl::callbackProcessingInstruction( const xmlChar *target, const xmlChar *data )
 {
-    if (!pendingCharacters.isEmpty())
+    if (!pendingCharacters.empty())
         sendPendingCharacters();
     Entity& rEntity = getEntity();
     Event& rEvent = rEntity.getEvent( PROCESSING_INSTRUCTION );


More information about the Libreoffice-commits mailing list