[Libreoffice-commits] core.git: formula/source include/formula sc/inc sc/source

Michael Meeks michael.meeks at collabora.com
Wed May 21 02:06:51 PDT 2014


 formula/source/core/api/token.cxx |   18 ++++++++++++++++++
 include/formula/tokenarray.hxx    |    1 +
 sc/inc/tokenarray.hxx             |    3 +++
 sc/source/core/tool/token.cxx     |   12 ++++++++++++
 sc/source/filter/xml/xmlcelli.cxx |   13 +++++++------
 5 files changed, 41 insertions(+), 6 deletions(-)

New commits:
commit c07b8dedf7b1d0ddb2c97368e1634432974632db
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon May 19 20:23:07 2014 +0100

    ODS load perf: transfer ownership of the ScTokenArray to save cycles.
    
    Add API to wnsure we don't end up allocating 32k bytes of tokens
    for each ScFormulaToken, as happens when you Add a token to a new
    empty ScTokenArray.
    
    Change-Id: Ib12a3065eb513243a2146ebb009fbaa650385dd9

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index c5d7da7..30b0e16 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -687,6 +687,24 @@ void FormulaTokenArray::Assign( const FormulaTokenArray& r )
     }
 }
 
+/// Optimisiation for efficiently creating StringXML placeholders
+void FormulaTokenArray::Assign( sal_uInt16 nCode, FormulaToken **pTokens )
+{
+    assert( nLen = 0 );
+    assert( pCode == NULL );
+
+    nLen = nCode;
+    pCode = new FormulaToken*[ nLen ];
+
+    for( sal_uInt16 i = 0; i < nLen; i++ )
+    {
+        FormulaToken *t = pTokens[ i ];
+        assert( t->GetOpCode() == ocStringXML );
+        pCode[ i ] = t;
+        t->IncRef();
+    }
+}
+
 FormulaTokenArray& FormulaTokenArray::operator=( const FormulaTokenArray& rArr )
 {
     Clear();
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index 5654a31..dcc8dc9 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -82,6 +82,7 @@ protected:
 
 protected:
     void                    Assign( const FormulaTokenArray& );
+    void                    Assign( sal_uInt16 nCode, FormulaToken **pTokens );
 
     /// Also used by the compiler. The token MUST had been allocated with new!
     FormulaToken*           Add( FormulaToken* );
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index c2191a8..9538819 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -110,6 +110,9 @@ public:
         NULL if there is no pCode (which actually would be caller's fault). */
     formula::FormulaToken* MergeRangeReference( const ScAddress & rPos );
 
+    /// Assign XML string placeholder to the array
+    void AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp );
+
     /// Assignment with references to ScToken entries (not copied!)
     ScTokenArray& operator=( const ScTokenArray& );
 
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 4f4cbf6..4ac537f 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -2083,6 +2083,18 @@ FormulaToken* ScTokenArray::AddColRowName( const ScSingleRefData& rRef )
     return Add( new ScSingleRefToken( rRef, ocColRowName ) );
 }
 
+void ScTokenArray::AssignXMLString( const OUString &rText, const OUString &rFormulaNmsp )
+{
+    sal_uInt16 nTokens = 1;
+    FormulaToken *aTokens[2];
+
+    aTokens[0] = new FormulaStringOpToken( ocStringXML, rText );
+    if( !rFormulaNmsp.isEmpty() )
+        aTokens[ nTokens++ ] = new FormulaStringOpToken( ocStringXML, rFormulaNmsp );
+
+    Assign( nTokens, aTokens );
+}
+
 bool ScTokenArray::GetAdjacentExtendOfOuterFuncRefs( SCCOLROW& nExtend,
         const ScAddress& rPos, ScDirection eDir )
 {
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index b09f90c..4e4c552 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1362,7 +1362,6 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
     ScDocumentImport& rDoc = rXMLImport.GetDoc();
 
     OUString aText = maFormula->first;
-    OUString aFormulaNmsp = maFormula->second;
 
     ::boost::scoped_ptr<ScExternalRefManager::ApiGuard> pExtRefGuard (
             new ScExternalRefManager::ApiGuard(pDoc));
@@ -1372,13 +1371,15 @@ void ScXMLTableRowCellContext::PutFormulaCell( const ScAddress& rCellPos )
         if ( aText[0] == '=' && aText.getLength() > 1 )
         {
             // temporary formula string as string tokens
-            boost::scoped_ptr<ScTokenArray> pCode(new ScTokenArray);
-            pCode->AddStringXML( aText );
-            if( (eGrammar == formula::FormulaGrammar::GRAM_EXTERNAL) && !aFormulaNmsp.isEmpty() )
-                pCode->AddStringXML( aFormulaNmsp );
+            ScTokenArray *pCode = new ScTokenArray();
+
+            OUString aFormulaNmsp = maFormula->second;
+            if( eGrammar != formula::FormulaGrammar::GRAM_EXTERNAL )
+                aFormulaNmsp = OUString();
+            pCode->AssignXMLString( aText, aFormulaNmsp );
 
             rDoc.getDoc().IncXMLImportedFormulaCount( aText.getLength() );
-            ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, *pCode, eGrammar, MM_NONE);
+            ScFormulaCell* pNewCell = new ScFormulaCell(pDoc, rCellPos, pCode, eGrammar, MM_NONE);
             SetFormulaCell(pNewCell);
             rDoc.setFormulaCell(rCellPos, pNewCell);
 


More information about the Libreoffice-commits mailing list