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

Kohei Yoshida kohei.yoshida at collabora.com
Mon Apr 14 15:34:09 PDT 2014


 formula/source/core/api/token.cxx |   25 +++++++++++++++----------
 include/formula/tokenarray.hxx    |    9 +++++++--
 sc/inc/tokenarray.hxx             |    5 ++++-
 sc/source/core/tool/token.cxx     |   27 ++++++++++++++-------------
 sc/source/ui/formdlg/formula.cxx  |    2 +-
 sc/source/ui/unoobj/tokenuno.cxx  |    2 +-
 6 files changed, 42 insertions(+), 28 deletions(-)

New commits:
commit 625c595fc30d2e6153735dc2ed2359ff4f8a1e3a
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Apr 14 18:32:57 2014 -0400

    fdo#76294: Intern strings in AddFormulaToken() as well.
    
    And a whole bunch of changes needed to make that happen.
    
    Change-Id: Idd98fbc99322c0d72fb0a7848d89cb1a6abc88b6

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index ecfb02a..197d62f 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -29,6 +29,7 @@
 #include "formula/tokenarray.hxx"
 #include "formula/FormulaCompiler.hxx"
 #include <formula/compiler.hrc>
+#include <svl/sharedstringpool.hxx>
 
 namespace formula
 {
@@ -297,12 +298,13 @@ FormulaJumpToken::~FormulaJumpToken()
 }
 
 
-bool FormulaTokenArray::AddFormulaToken(const sheet::FormulaToken& _aToken,ExternalReferenceHelper* /*_pRef*/)
+bool FormulaTokenArray::AddFormulaToken(
+    const sheet::FormulaToken& rToken, svl::SharedStringPool& rSPool, ExternalReferenceHelper* /*pExtRef*/)
 {
     bool bError = false;
-    const OpCode eOpCode = static_cast<OpCode>(_aToken.OpCode);      //! assuming equal values for the moment
+    const OpCode eOpCode = static_cast<OpCode>(rToken.OpCode);      //! assuming equal values for the moment
 
-    const uno::TypeClass eClass = _aToken.Data.getValueTypeClass();
+    const uno::TypeClass eClass = rToken.Data.getValueTypeClass();
     switch ( eClass )
     {
         case uno::TypeClass_VOID:
@@ -312,14 +314,14 @@ bool FormulaTokenArray::AddFormulaToken(const sheet::FormulaToken& _aToken,Exter
         case uno::TypeClass_DOUBLE:
             // double is only used for "push"
             if ( eOpCode == ocPush )
-                AddDouble( _aToken.Data.get<double>() );
+                AddDouble( rToken.Data.get<double>() );
             else
                 bError = true;
             break;
         case uno::TypeClass_LONG:
             {
                 // long is svIndex, used for name / database area, or "byte" for spaces
-                sal_Int32 nValue = _aToken.Data.get<sal_Int32>();
+                sal_Int32 nValue = rToken.Data.get<sal_Int32>();
                 if ( eOpCode == ocDBArea )
                     AddToken( formula::FormulaIndexToken( eOpCode, static_cast<sal_uInt16>(nValue) ) );
                 else if ( eOpCode == ocSpaces )
@@ -330,9 +332,9 @@ bool FormulaTokenArray::AddFormulaToken(const sheet::FormulaToken& _aToken,Exter
             break;
         case uno::TypeClass_STRING:
             {
-                OUString aStrVal( _aToken.Data.get<OUString>() );
+                OUString aStrVal( rToken.Data.get<OUString>() );
                 if ( eOpCode == ocPush )
-                    AddString( aStrVal );
+                    AddString(rSPool.intern(aStrVal));
                 else if ( eOpCode == ocBad )
                     AddBad( aStrVal );
                 else if ( eOpCode == ocStringXML )
@@ -348,13 +350,16 @@ bool FormulaTokenArray::AddFormulaToken(const sheet::FormulaToken& _aToken,Exter
     } // switch ( eClass )
     return bError;
 }
-bool FormulaTokenArray::Fill(const uno::Sequence< sheet::FormulaToken >& _aSequence,ExternalReferenceHelper* _pRef)
+
+bool FormulaTokenArray::Fill(
+    const uno::Sequence<sheet::FormulaToken>& rSequence,
+    svl::SharedStringPool& rSPool, ExternalReferenceHelper* pExtRef )
 {
     bool bError = false;
-    const sal_Int32 nCount = _aSequence.getLength();
+    const sal_Int32 nCount = rSequence.getLength();
     for (sal_Int32 nPos=0; nPos<nCount; nPos++)
     {
-        bool bOneError = AddFormulaToken( _aSequence[nPos] ,_pRef);
+        bool bOneError = AddFormulaToken(rSequence[nPos], rSPool, pExtRef);
         if (bOneError)
         {
             AddOpCode( ocErrName);  // add something that indicates an error
diff --git a/include/formula/tokenarray.hxx b/include/formula/tokenarray.hxx
index fba33e8..5654a31 100644
--- a/include/formula/tokenarray.hxx
+++ b/include/formula/tokenarray.hxx
@@ -30,6 +30,7 @@
 namespace svl {
 
 class SharedString;
+class SharedStringPool;
 
 }
 
@@ -202,14 +203,18 @@ public:
         Derived classes must overload it when they want to support derived classes from FormulaToken.
         @return true        when an error occurs
     */
-    virtual bool AddFormulaToken(const com::sun::star::sheet::FormulaToken& _aToken, ExternalReferenceHelper* _pRef = NULL);
+    virtual bool AddFormulaToken(
+        const css::sheet::FormulaToken& rToken, svl::SharedStringPool& rSPool,
+        ExternalReferenceHelper* pExtRef );
 
     /** fill the array with the tokens from the sequence.
         It calls AddFormulaToken for each token in the list.
         @param  _aSequence  the token to add
         @return true        when an error occurs
     */
-    bool Fill(const com::sun::star::uno::Sequence< com::sun::star::sheet::FormulaToken >& _aSequence, ExternalReferenceHelper* _pRef = NULL);
+    bool Fill(
+        const css::uno::Sequence<css::sheet::FormulaToken>& rSequence,
+        svl::SharedStringPool& rSPool, ExternalReferenceHelper* pExtRef );
 
     /**
      * Do some checking based on the individual tokens. For now, we use this
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index a1fae5b..1ea6658 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -83,7 +83,10 @@ public:
                                 const ScAddress& rPos, ScDirection );
 
     formula::FormulaToken* AddRawToken( const ScRawToken& );
-    virtual bool AddFormulaToken(const com::sun::star::sheet::FormulaToken& _aToken,formula::ExternalReferenceHelper* _pRef) SAL_OVERRIDE;
+    virtual bool AddFormulaToken(
+        const css::sheet::FormulaToken& rToken,
+        svl::SharedStringPool& rSPool,
+        formula::ExternalReferenceHelper* _pRef) SAL_OVERRIDE;
     virtual void CheckToken( const formula::FormulaToken& r ) SAL_OVERRIDE;
     virtual formula::FormulaToken* AddOpCode( OpCode eCode ) SAL_OVERRIDE;
     /** ScSingleRefToken with ocPush. */
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 7af3123..58f64cc 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -1175,25 +1175,26 @@ bool ScHybridCellToken::operator==( const FormulaToken& r ) const
 
 
 
-bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _aToken,formula::ExternalReferenceHelper* _pRef)
+bool ScTokenArray::AddFormulaToken(
+    const css::sheet::FormulaToken& rToken, svl::SharedStringPool& rSPool, formula::ExternalReferenceHelper* pExtRef)
 {
-    bool bError = FormulaTokenArray::AddFormulaToken(_aToken,_pRef);
+    bool bError = FormulaTokenArray::AddFormulaToken(rToken, rSPool, pExtRef);
     if ( bError )
     {
         bError = false;
-        const OpCode eOpCode = static_cast<OpCode>(_aToken.OpCode);      //! assuming equal values for the moment
+        const OpCode eOpCode = static_cast<OpCode>(rToken.OpCode);      //! assuming equal values for the moment
 
-        const uno::TypeClass eClass = _aToken.Data.getValueTypeClass();
+        const uno::TypeClass eClass = rToken.Data.getValueTypeClass();
         switch ( eClass )
         {
             case uno::TypeClass_STRUCT:
                 {
-                    uno::Type aType = _aToken.Data.getValueType();
+                    uno::Type aType = rToken.Data.getValueType();
                     if ( aType.equals( cppu::UnoType<sheet::SingleReference>::get() ) )
                     {
                         ScSingleRefData aSingleRef;
                         sheet::SingleReference aApiRef;
-                        _aToken.Data >>= aApiRef;
+                        rToken.Data >>= aApiRef;
                         lcl_SingleRefToCalc( aSingleRef, aApiRef );
                         if ( eOpCode == ocPush )
                             AddSingleReference( aSingleRef );
@@ -1206,7 +1207,7 @@ bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _a
                     {
                         ScComplexRefData aComplRef;
                         sheet::ComplexReference aApiRef;
-                        _aToken.Data >>= aApiRef;
+                        rToken.Data >>= aApiRef;
                         lcl_SingleRefToCalc( aComplRef.Ref1, aApiRef.Reference1 );
                         lcl_SingleRefToCalc( aComplRef.Ref2, aApiRef.Reference2 );
 
@@ -1218,7 +1219,7 @@ bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _a
                     else if ( aType.equals( cppu::UnoType<sheet::NameToken>::get() ) )
                     {
                         sheet::NameToken aTokenData;
-                        _aToken.Data >>= aTokenData;
+                        rToken.Data >>= aTokenData;
                         if ( eOpCode == ocName )
                             AddRangeName(aTokenData.Index, aTokenData.Global);
                         else if (eOpCode == ocDBArea)
@@ -1229,7 +1230,7 @@ bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _a
                     else if ( aType.equals( cppu::UnoType<sheet::ExternalReference>::get() ) )
                     {
                         sheet::ExternalReference aApiExtRef;
-                        if( (eOpCode == ocPush) && (_aToken.Data >>= aApiExtRef) && (0 <= aApiExtRef.Index) && (aApiExtRef.Index <= SAL_MAX_UINT16) )
+                        if( (eOpCode == ocPush) && (rToken.Data >>= aApiExtRef) && (0 <= aApiExtRef.Index) && (aApiExtRef.Index <= SAL_MAX_UINT16) )
                         {
                             sal_uInt16 nFileId = static_cast< sal_uInt16 >( aApiExtRef.Index );
                             sheet::SingleReference aApiSRef;
@@ -1239,7 +1240,7 @@ bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _a
                             {
                                 // try to resolve cache index to sheet name
                                 size_t nCacheId = static_cast< size_t >( aApiSRef.Sheet );
-                                OUString aTabName = _pRef->getCacheTableName( nFileId, nCacheId );
+                                OUString aTabName = pExtRef->getCacheTableName( nFileId, nCacheId );
                                 if( !aTabName.isEmpty() )
                                 {
                                     ScSingleRefData aSingleRef;
@@ -1254,7 +1255,7 @@ bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _a
                             {
                                 // try to resolve cache index to sheet name.
                                 size_t nCacheId = static_cast< size_t >( aApiCRef.Reference1.Sheet );
-                                OUString aTabName = _pRef->getCacheTableName( nFileId, nCacheId );
+                                OUString aTabName = pExtRef->getCacheTableName( nFileId, nCacheId );
                                 if( !aTabName.isEmpty() )
                                 {
                                     ScComplexRefData aComplRef;
@@ -1290,12 +1291,12 @@ bool ScTokenArray::AddFormulaToken(const com::sun::star::sheet::FormulaToken& _a
                 {
                     if ( eOpCode != ocPush )
                         bError = true;      // not an inline array
-                    else if (!_aToken.Data.getValueType().equals( getCppuType(
+                    else if (!rToken.Data.getValueType().equals( getCppuType(
                                     (uno::Sequence< uno::Sequence< uno::Any > > *)0)))
                         bError = true;      // unexpected sequence type
                     else
                     {
-                        ScMatrixRef xMat = ScSequenceToMatrix::CreateMixedMatrix( _aToken.Data);
+                        ScMatrixRef xMat = ScSequenceToMatrix::CreateMixedMatrix( rToken.Data);
                         if (xMat)
                             AddMatrix( xMat);
                         else
diff --git a/sc/source/ui/formdlg/formula.cxx b/sc/source/ui/formdlg/formula.cxx
index f8bd44e..c2bcb3e 100644
--- a/sc/source/ui/formdlg/formula.cxx
+++ b/sc/source/ui/formdlg/formula.cxx
@@ -655,7 +655,7 @@ SAL_WNODEPRECATED_DECLARATIONS_PUSH
 ::std::auto_ptr<formula::FormulaTokenArray> ScFormulaDlg::convertToTokenArray(const uno::Sequence< sheet::FormulaToken >& _aTokenList)
 {
     ::std::auto_ptr<formula::FormulaTokenArray> pArray(new ScTokenArray());
-    pArray->Fill( _aTokenList, pDoc->GetExternalRefManager());
+    pArray->Fill(_aTokenList, pDoc->GetSharedStringPool(), pDoc->GetExternalRefManager());
     return pArray;
 }
 // for mysterious reasons Apple llvm-g++ 4.2.1 needs these explicit
diff --git a/sc/source/ui/unoobj/tokenuno.cxx b/sc/source/ui/unoobj/tokenuno.cxx
index 98d8153..59bd144 100644
--- a/sc/source/ui/unoobj/tokenuno.cxx
+++ b/sc/source/ui/unoobj/tokenuno.cxx
@@ -363,7 +363,7 @@ static void lcl_SingleRefToApi( sheet::SingleReference& rAPI, const ScSingleRefD
 bool ScTokenConversion::ConvertToTokenArray( ScDocument& rDoc,
         ScTokenArray& rTokenArray, const uno::Sequence<sheet::FormulaToken>& rSequence )
 {
-    return !rTokenArray.Fill(rSequence,rDoc.GetExternalRefManager());
+    return !rTokenArray.Fill(rSequence, rDoc.GetSharedStringPool(), rDoc.GetExternalRefManager());
 }
 
 bool ScTokenConversion::ConvertToTokenSequence( const ScDocument& rDoc,


More information about the Libreoffice-commits mailing list