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

Eike Rathke erack at redhat.com
Tue Jan 5 14:42:47 PST 2016


 formula/source/core/api/token.cxx |    8 ++++----
 include/formula/tokenarray.hxx    |    5 +++++
 sc/source/core/tool/compiler.cxx  |   16 ++++++++++------
 3 files changed, 19 insertions(+), 10 deletions(-)

New commits:
commit 22e5170af74c635cf55d089f97946b6dc86f82ad
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Jan 5 22:54:10 2016 +0100

    create closing bracket token only when necessary
    
    Change-Id: Ifb705279ff01d4c886678a183de0499ec5bb119e

diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index aa9e1b9..a9bbc68 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -4320,15 +4320,19 @@ ScTokenArray* ScCompiler::CompileString( const OUString& rFormula )
                 aCorrectedFormula += mxSymbols->getSymbol(ocArrayClose);
         }
 
-        FormulaByteToken aToken( ocClose );
-        while( nBrackets-- )
+        if (nBrackets)
         {
-            if( !pArr->AddToken( aToken ) )
+            FormulaByteToken aToken( ocClose );
+            while( nBrackets-- )
             {
-                SetError(errCodeOverflow); break;
+                if( !pArr->AddToken( aToken ) )
+                {
+                    SetError(errCodeOverflow);
+                    break;  // while
+                }
+                if ( bAutoCorrect )
+                    aCorrectedFormula += mxSymbols->getSymbol(ocClose);
             }
-            if ( bAutoCorrect )
-                aCorrectedFormula += mxSymbols->getSymbol(ocClose);
         }
     }
     if ( nForced >= 2 )
commit 4ae7b66286f391839b0d8d6c5a73ee7849eb4d1f
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Jan 5 22:26:45 2016 +0100

    use new'ed FormulaToken and FormulaTokenArray::Add()
    
    ... instead of a temporary instance and AddToken() that just clones it
    again.
    
    Add function comment describing the difference.
    
    Change-Id: I3f089965d394b33d7bbbb9a1c3f69dc1c4182fd2

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index c16f3ca..3668b4d 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -395,11 +395,11 @@ bool FormulaTokenArray::AddFormulaToken(
                 // long is svIndex, used for name / database area, or "byte" for spaces
                 sal_Int32 nValue = rToken.Data.get<sal_Int32>();
                 if ( eOpCode == ocDBArea )
-                    AddToken( formula::FormulaIndexToken( eOpCode, static_cast<sal_uInt16>(nValue) ) );
+                    Add( new formula::FormulaIndexToken( eOpCode, static_cast<sal_uInt16>(nValue) ) );
                 else if ( eOpCode == ocTableRef )
                     bError = true;  /* TODO: implementation */
                 else if ( eOpCode == ocSpaces )
-                    AddToken( formula::FormulaByteToken( ocSpaces, static_cast<sal_uInt8>(nValue) ) );
+                    Add( new formula::FormulaByteToken( ocSpaces, static_cast<sal_uInt8>(nValue) ) );
                 else
                     bError = true;
             }
@@ -414,7 +414,7 @@ bool FormulaTokenArray::AddFormulaToken(
                 else if ( eOpCode == ocStringXML )
                     AddStringXML( aStrVal );
                 else if ( eOpCode == ocExternal || eOpCode == ocMacro )
-                    AddToken( formula::FormulaExternalToken( eOpCode, aStrVal ) );
+                    Add( new formula::FormulaExternalToken( eOpCode, aStrVal ) );
                 else
                     bError = true;      // unexpected string: don't know what to do with it
             }
@@ -1600,7 +1600,7 @@ FormulaToken* FormulaTokenArray::AddOpCode( OpCode eOp )
             pRet = new FormulaByteToken( eOp, 0, false );
             break;
     }
-    return AddToken( *pRet );
+    return Add( pRet );
 }
 
 void FormulaTokenArray::ReinternStrings( svl::SharedStringPool& rPool )
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index 292b318..bf3056a 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -296,7 +296,12 @@ public:
      */
     virtual void CheckToken( const FormulaToken& t );
 
+    /** Clones the token and then adds the clone to the pCode array.
+        For just new'ed tokens use Add() instead of cloning it again.
+        Use this AddToken() when adding a token from another origin.
+     */
     FormulaToken* AddToken( const FormulaToken& );
+
     FormulaToken* AddString( const svl::SharedString& rStr );
     FormulaToken* AddDouble( double fVal );
     FormulaToken* AddExternal( const sal_Unicode* pStr );


More information about the Libreoffice-commits mailing list