[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue Mar 11 17:09:48 PDT 2014


 sc/source/filter/inc/formulabuffer.hxx    |   15 +++++++---
 sc/source/filter/inc/worksheethelper.hxx  |    5 ++-
 sc/source/filter/oox/formulabuffer.cxx    |   44 +++++++++++++++++++++++-------
 sc/source/filter/oox/sheetdatacontext.cxx |    4 +-
 sc/source/filter/oox/worksheethelper.cxx  |    6 ++--
 5 files changed, 54 insertions(+), 20 deletions(-)

New commits:
commit 13c4e40ad0b199199e28e01103e0fc67c4a0bf14
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Mon Mar 10 17:03:52 2014 -0400

    fdo#74747: Make use of cached string formula results.
    
    Just like we do with cached numeric formula results.
    
    Change-Id: Ib8b311b540caeb47d8c2162a456f7490c5882ad5
    (cherry picked from commit aa5ad7b8096cd15a55c467b1a23d03849aeb870d)
    Reviewed-on: https://gerrit.libreoffice.org/8526
    Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/source/filter/inc/formulabuffer.hxx b/sc/source/filter/inc/formulabuffer.hxx
index 6be0a25..5fdc248 100644
--- a/sc/source/filter/inc/formulabuffer.hxx
+++ b/sc/source/filter/inc/formulabuffer.hxx
@@ -77,13 +77,19 @@ public:
         TokenRangeAddressItem( const TokenAddressItem& rTokenAndAddress, const ::com::sun::star::table::CellRangeAddress& rCellRangeAddress ) : maTokenAndAddress( rTokenAndAddress ), maCellRangeAddress( rCellRangeAddress ) {}
     };
 
+    struct FormulaValue
+    {
+        com::sun::star::table::CellAddress maCellAddress;
+        OUString maValueStr;
+        sal_Int32 mnCellType;
+    };
     typedef std::pair<com::sun::star::table::CellAddress, double> ValueAddressPair;
 
     struct SheetItem
     {
         std::vector<TokenAddressItem>* mpCellFormulas;
         std::vector<TokenRangeAddressItem>* mpArrayFormulas;
-        std::vector<ValueAddressPair>* mpCellFormulaValues;
+        std::vector<FormulaValue>* mpCellFormulaValues;
         std::vector<SharedFormulaEntry>* mpSharedFormulaEntries;
         std::vector<SharedFormulaDesc>* mpSharedFormulaIDs;
 
@@ -98,7 +104,7 @@ private:
     typedef ::std::vector< std::vector<SharedFormulaDesc> > SheetToSharedFormulaid;
     // sheet -> stuff needed to create shared formulae
     typedef ::std::vector< std::vector<SharedFormulaEntry> >  SheetToFormulaEntryArray;
-    typedef ::std::vector< std::vector<ValueAddressPair> > FormulaValueArray;
+    typedef ::std::vector< std::vector<FormulaValue> > FormulaValueArray;
 
     osl::Mutex maMtxData;
     FormulaDataArray         maCellFormulas;
@@ -118,8 +124,9 @@ public:
         const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId,
         const OUString& rCellValue, sal_Int32 nValueType );
 
-    void                setCellFormulaValue( const ::css::table::CellAddress& rAddress,
-                                             double fValue );
+    void setCellFormulaValue(
+        const css::table::CellAddress& rAddress, const OUString& rValueStr, sal_Int32 nCellType );
+
     void                setCellArrayFormula( const ::css::table::CellRangeAddress& rRangeAddress,
                                              const ::css::table::CellAddress& rTokenAddress,
                                              const OUString& );
diff --git a/sc/source/filter/inc/worksheethelper.hxx b/sc/source/filter/inc/worksheethelper.hxx
index 9e23161..a07019a 100644
--- a/sc/source/filter/inc/worksheethelper.hxx
+++ b/sc/source/filter/inc/worksheethelper.hxx
@@ -324,8 +324,9 @@ public:
         const com::sun::star::table::CellRangeAddress& rRange,
         sal_Int32 nSharedId, const OUString& rTokens );
 
-    void                setCellFormulaValue( const ::com::sun::star::table::CellAddress& rAddress,
-                            double fValue  );
+    void setCellFormulaValue(
+        const css::table::CellAddress& rAddress, const OUString& rValueStr, sal_Int32 nCellType );
+
 private:
     WorksheetGlobals&   mrSheetGlob;
 };
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index ca241a6..e5a2874 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -28,6 +28,7 @@
 #include "externalrefmgr.hxx"
 #include "tokenstringcontext.hxx"
 #include "oox/token/tokens.hxx"
+#include <svl/sharedstringpool.hxx>
 
 using namespace com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -256,19 +257,39 @@ void applyArrayFormulas(
 }
 
 void applyCellFormulaValues(
-    ScDocumentImport& rDoc, const std::vector<FormulaBuffer::ValueAddressPair>& rVector )
+    ScDocumentImport& rDoc, const std::vector<FormulaBuffer::FormulaValue>& rVector )
 {
-    std::vector<FormulaBuffer::ValueAddressPair>::const_iterator it = rVector.begin(), itEnd = rVector.end();
+    svl::SharedStringPool& rStrPool = rDoc.getDoc().GetSharedStringPool();
+
+    std::vector<FormulaBuffer::FormulaValue>::const_iterator it = rVector.begin(), itEnd = rVector.end();
     for (; it != itEnd; ++it)
     {
         ScAddress aCellPos;
-        ScUnoConversion::FillScAddress(aCellPos, it->first);
+        ScUnoConversion::FillScAddress(aCellPos, it->maCellAddress);
         ScFormulaCell* pCell = rDoc.getDoc().GetFormulaCell(aCellPos);
-        if (pCell)
+        const OUString& rValueStr = it->maValueStr;
+        if (!pCell)
+            continue;
+
+        switch (it->mnCellType)
         {
-            pCell->SetHybridDouble(it->second);
-            pCell->ResetDirty();
-            pCell->SetChanged(false);
+            case XML_n:
+            {
+                pCell->SetResultDouble(rValueStr.toDouble());
+                pCell->ResetDirty();
+                pCell->SetChanged(false);
+            }
+            break;
+            case XML_str:
+            {
+                svl::SharedString aSS = rStrPool.intern(rValueStr);
+                pCell->SetResultToken(new formula::FormulaStringToken(aSS));
+                pCell->ResetDirty();
+                pCell->SetChanged(false);
+            }
+            break;
+            default:
+                ;
         }
     }
 }
@@ -470,10 +491,15 @@ void FormulaBuffer::setCellArrayFormula( const ::com::sun::star::table::CellRang
     maCellArrayFormulas[ rRangeAddress.Sheet ].push_back( TokenRangeAddressItem( tokenPair, rRangeAddress ) );
 }
 
-void FormulaBuffer::setCellFormulaValue( const ::com::sun::star::table::CellAddress& rAddress, double fValue )
+void FormulaBuffer::setCellFormulaValue(
+        const css::table::CellAddress& rAddress, const OUString& rValueStr, sal_Int32 nCellType )
 {
     assert( rAddress.Sheet >= 0 && (size_t)rAddress.Sheet < maCellFormulaValues.size() );
-    maCellFormulaValues[ rAddress.Sheet ].push_back( ValueAddressPair( rAddress, fValue ) );
+    FormulaValue aVal;
+    aVal.maCellAddress = rAddress;
+    aVal.maValueStr = rValueStr;
+    aVal.mnCellType = nCellType;
+    maCellFormulaValues[rAddress.Sheet].push_back(aVal);
 }
 
 }}
diff --git a/sc/source/filter/oox/sheetdatacontext.cxx b/sc/source/filter/oox/sheetdatacontext.cxx
index c22930f..4bd841d 100644
--- a/sc/source/filter/oox/sheetdatacontext.cxx
+++ b/sc/source/filter/oox/sheetdatacontext.cxx
@@ -161,8 +161,8 @@ void SheetDataContext::onEndElement()
 
                 // If a number cell has some preloaded value, stick it into the buffer
                 // but do this only for real cell formulas (not array, shared etc.)
-                if( !( maCellValue.isEmpty() ) && ( maCellData.mnCellType == XML_n ) )
-                    setCellFormulaValue( maCellData.maCellAddr, maCellValue.toDouble() );
+                if (!maCellValue.isEmpty())
+                    setCellFormulaValue(maCellData.maCellAddr, maCellValue, maCellData.mnCellType);
                 break;
 
             case XML_shared:
diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx
index b334052..0eb1ec7 100644
--- a/sc/source/filter/oox/worksheethelper.cxx
+++ b/sc/source/filter/oox/worksheethelper.cxx
@@ -1578,10 +1578,10 @@ void WorksheetHelper::putValue( const CellAddress& rAddress, double fValue )
     getDocImport().setNumericCell(aAddress, fValue);
 }
 
-void WorksheetHelper::setCellFormulaValue( const ::com::sun::star::table::CellAddress& rAddress,
-                            double fValue  )
+void WorksheetHelper::setCellFormulaValue(
+    const css::table::CellAddress& rAddress, const OUString& rValueStr, sal_Int32 nCellType )
 {
-    getFormulaBuffer().setCellFormulaValue( rAddress, fValue );
+    getFormulaBuffer().setCellFormulaValue(rAddress, rValueStr, nCellType);
 }
 
 void WorksheetHelper::putString( const CellAddress& rAddress, const OUString& rText )


More information about the Libreoffice-commits mailing list