[Libreoffice-commits] core.git: 2 commits - sc/inc sc/Library_sc.mk sc/source

Kohei Yoshida kohei.yoshida at gmail.com
Mon Jul 1 15:55:56 PDT 2013


 sc/Library_sc.mk                         |    1 
 sc/inc/addincol.hxx                      |    4 
 sc/inc/externalrefmgr.hxx                |    2 
 sc/inc/queryparam.hxx                    |    2 
 sc/inc/rangeseq.hxx                      |    2 
 sc/inc/scmatrix.hxx                      |   14 --
 sc/inc/token.hxx                         |   56 ++-------
 sc/inc/tokenarray.hxx                    |    1 
 sc/inc/types.hxx                         |    8 +
 sc/source/core/data/column2.cxx          |    1 
 sc/source/core/data/dociter.cxx          |    1 
 sc/source/core/data/documen4.cxx         |    1 
 sc/source/core/data/table1.cxx           |    1 
 sc/source/core/data/validat.cxx          |    6 -
 sc/source/core/inc/ddelink.hxx           |    8 -
 sc/source/core/inc/doubleref.hxx         |    2 
 sc/source/core/inc/interpre.hxx          |    2 
 sc/source/core/inc/jumpmatrix.hxx        |  179 ++++---------------------------
 sc/source/core/tool/addincol.cxx         |    8 -
 sc/source/core/tool/compiler.cxx         |    1 
 sc/source/core/tool/ddelink.cxx          |   15 ++
 sc/source/core/tool/doubleref.cxx        |    1 
 sc/source/core/tool/formulagroup.cxx     |    2 
 sc/source/core/tool/formularesult.cxx    |    1 
 sc/source/core/tool/interpr5.cxx         |   92 ++++++++++-----
 sc/source/core/tool/jumpmatrix.cxx       |  173 +++++++++++++++++++++++++++++
 sc/source/core/tool/queryparam.cxx       |    1 
 sc/source/core/tool/rangenam.cxx         |    2 
 sc/source/core/tool/scmatrix.cxx         |  156 +++++++++++++++++++++++++++
 sc/source/core/tool/token.cxx            |   40 ++++++
 sc/source/filter/excel/excform.cxx       |    2 
 sc/source/filter/excel/xeformula.cxx     |    1 
 sc/source/filter/excel/xehelper.cxx      |    1 
 sc/source/filter/excel/xihelper.cxx      |    8 +
 sc/source/filter/excel/xilink.cxx        |    3 
 sc/source/filter/inc/xihelper.hxx        |    7 -
 sc/source/filter/inc/xilink.hxx          |    2 
 sc/source/filter/xml/xmlcelli.cxx        |    1 
 sc/source/ui/docshell/externalrefmgr.cxx |    1 
 sc/source/ui/unoobj/chart2uno.cxx        |    1 
 sc/source/ui/unoobj/linkuno.cxx          |    1 
 41 files changed, 555 insertions(+), 256 deletions(-)

New commits:
commit ed76237e41ecdb58f524e14ea6b8866f8dacf6a9
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Jul 1 16:04:35 2013 -0400

    Reduce dependency on the matrix header.
    
    Change-Id: Iade09d108aec78f8cbe92f9103f206d0c99fab8e

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 836f87f..5815fd0 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -225,6 +225,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/core/tool/interpr5 \
 	sc/source/core/tool/interpr6 \
 	sc/source/core/tool/interpr7 \
+	sc/source/core/tool/jumpmatrix \
 	sc/source/core/tool/lookupcache \
 	sc/source/core/tool/navicfg \
 	sc/source/core/tool/odffmap \
diff --git a/sc/inc/addincol.hxx b/sc/inc/addincol.hxx
index 15abd4c..4b440a2 100644
--- a/sc/inc/addincol.hxx
+++ b/sc/inc/addincol.hxx
@@ -32,7 +32,7 @@
 #include "scdllapi.h"
 #include <rtl/ustring.hxx>
 
-#include "scmatrix.hxx"
+#include "types.hxx"
 
 #include <boost/unordered_map.hpp>
 
@@ -233,7 +233,7 @@ public:
     bool                HasVarRes() const       { return ( xVarRes.is() ); }
     double              GetValue() const        { return fValue; }
     const OUString&     GetString() const       { return aString; }
-    ScMatrixRef         GetMatrix() const       { return xMatrix; }
+    ScMatrixRef         GetMatrix() const;
     com::sun::star::uno::Reference<com::sun::star::sheet::XVolatileResult>
                         GetVarRes() const       { return xVarRes; }
 };
diff --git a/sc/inc/externalrefmgr.hxx b/sc/inc/externalrefmgr.hxx
index 0a115c0..4e39a5d 100644
--- a/sc/inc/externalrefmgr.hxx
+++ b/sc/inc/externalrefmgr.hxx
@@ -29,7 +29,7 @@
 #include "vcl/timer.hxx"
 #include "svl/zforlist.hxx"
 #include "svl/lstner.hxx"
-#include "scmatrix.hxx"
+#include "types.hxx"
 #include "rangelst.hxx"
 #include "formula/token.hxx"
 
diff --git a/sc/inc/queryparam.hxx b/sc/inc/queryparam.hxx
index 26d2d1b..0d814cd 100644
--- a/sc/inc/queryparam.hxx
+++ b/sc/inc/queryparam.hxx
@@ -21,7 +21,7 @@
 #define SC_QUERYPARAM_HXX
 
 #include "global.hxx"
-#include "scmatrix.hxx"
+#include "types.hxx"
 
 #include <boost/ptr_container/ptr_vector.hpp>
 
diff --git a/sc/inc/rangeseq.hxx b/sc/inc/rangeseq.hxx
index bd8a900..b13233d 100644
--- a/sc/inc/rangeseq.hxx
+++ b/sc/inc/rangeseq.hxx
@@ -22,7 +22,7 @@
 
 #include <tools/solar.h>
 #include <com/sun/star/uno/Any.h>
-#include "scmatrix.hxx"
+#include "types.hxx"
 
 class SvNumberFormatter;
 class ScDocument;
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index ccb989f..47231b3 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -34,14 +34,6 @@ class ScInterpreter;
 class SvNumberFormatter;
 class ScMatrixImpl;
 
-typedef sal_uInt8 ScMatValType;
-const ScMatValType SC_MATVAL_VALUE     = 0x00;
-const ScMatValType SC_MATVAL_BOOLEAN   = 0x01;
-const ScMatValType SC_MATVAL_STRING    = 0x02;
-const ScMatValType SC_MATVAL_EMPTY     = SC_MATVAL_STRING | 0x04; // STRING plus flag
-const ScMatValType SC_MATVAL_EMPTYPATH = SC_MATVAL_EMPTY | 0x08;  // EMPTY plus flag
-const ScMatValType SC_MATVAL_NONVALUE  = SC_MATVAL_EMPTYPATH;     // mask of all non-value bits
-
 /**
  * Try NOT to use this struct.  This struct should go away in a hopefully
  * not so distant futture.
diff --git a/sc/inc/token.hxx b/sc/inc/token.hxx
index 109980f..116022a 100644
--- a/sc/inc/token.hxx
+++ b/sc/inc/token.hxx
@@ -26,7 +26,6 @@
 
 #include "formula/opcode.hxx"
 #include "refdata.hxx"
-#include "scmatrix.hxx"
 #include <tools/mempool.hxx>
 #include "scdllapi.h"
 #include "formula/IFunctionDescription.hxx"
@@ -163,10 +162,9 @@ class ScMatrixToken : public ScToken
 private:
             ScMatrixRef         pMatrix;
 public:
-                                ScMatrixToken( ScMatrixRef p ) :
-                                    ScToken( formula::svMatrix ), pMatrix( p ) {}
-                                ScMatrixToken( const ScMatrixToken& r ) :
-                                    ScToken( r ), pMatrix( r.pMatrix ) {}
+    ScMatrixToken( const ScMatrixRef& p );
+    ScMatrixToken( const ScMatrixToken& r );
+
     virtual const ScMatrix*     GetMatrix() const;
     virtual ScMatrix*           GetMatrix();
     virtual bool                operator==( const formula::FormulaToken& rToken ) const;
@@ -311,15 +309,11 @@ class SC_DLLPUBLIC ScMatrixCellResultToken : public ScToken
     virtual ScMatrix*           GetMatrix();
 
 protected:
-            ScConstMatrixRef    xMatrix;
-            formula::FormulaConstTokenRef     xUpperLeft;
+    ScConstMatrixRef xMatrix;
+    formula::FormulaConstTokenRef     xUpperLeft;
 public:
-                                ScMatrixCellResultToken( const ScConstMatrixRef& pMat, formula::FormulaToken* pUL ) :
-                                    ScToken( formula::svMatrixCell ),
-                                    xMatrix( pMat), xUpperLeft( pUL) {}
-                                ScMatrixCellResultToken( const ScMatrixCellResultToken& r ) :
-                                    ScToken( r ), xMatrix( r.xMatrix ),
-                                    xUpperLeft( r.xUpperLeft ) {}
+    ScMatrixCellResultToken( const ScConstMatrixRef& pMat, formula::FormulaToken* pUL );
+    ScMatrixCellResultToken( const ScMatrixCellResultToken& r );
     virtual double              GetDouble() const;
     virtual const String &      GetString() const;
     virtual const ScMatrix*     GetMatrix() const;
@@ -332,11 +326,7 @@ public:
                                             static_cast<formula::StackVar>(formula::svUnknown);
                                     }
     inline formula::FormulaConstTokenRef     GetUpperLeftToken() const   { return xUpperLeft; }
-            void                Assign( const ScMatrixCellResultToken & r )
-                                    {
-                                        xMatrix = r.xMatrix;
-                                        xUpperLeft = r.xUpperLeft;
-                                    }
+    void Assign( const ScMatrixCellResultToken & r );
 };
 
 
@@ -348,22 +338,10 @@ private:
             SCROW               nRows;
             SCCOL               nCols;
 public:
-    ScMatrixFormulaCellToken( SCCOL nC, SCROW nR, const ScConstMatrixRef& pMat, formula::FormulaToken* pUL ) :
-        ScMatrixCellResultToken(pMat, pUL),
-        nRows(nR), nCols(nC) {}
-
-                                ScMatrixFormulaCellToken( SCCOL nC, SCROW nR ) :
-                                    ScMatrixCellResultToken( NULL, NULL ),
-                                    nRows( nR ), nCols( nC ) {}
-                                ScMatrixFormulaCellToken( const ScMatrixFormulaCellToken& r ) :
-                                    ScMatrixCellResultToken( r ),
-                                    nRows( r.nRows ), nCols( r.nCols )
-                                    {
-                                        // xUpperLeft is modifiable through
-                                        // SetUpperLeftDouble(), so clone it.
-                                        if (xUpperLeft)
-                                            xUpperLeft = xUpperLeft->Clone();
-                                    }
+    ScMatrixFormulaCellToken( SCCOL nC, SCROW nR, const ScConstMatrixRef& pMat, formula::FormulaToken* pUL );
+    ScMatrixFormulaCellToken( SCCOL nC, SCROW nR );
+    ScMatrixFormulaCellToken( const ScMatrixFormulaCellToken& r );
+
     virtual bool                operator==( const formula::FormulaToken& rToken ) const;
     virtual FormulaToken*       Clone() const { return new ScMatrixFormulaCellToken(*this); }
             void                SetMatColsRows( SCCOL nC, SCROW nR )
@@ -399,13 +377,9 @@ public:
                                     nothing if xUpperLeft is of different type! */
             void                SetUpperLeftDouble( double f);
 
-                                /** Reset matrix and upper left, keep matrix
-                                    formula dimension. */
-            void                ResetResult()
-                                    {
-                                        xMatrix = NULL;
-                                        xUpperLeft = NULL;
-                                    }
+    /** Reset matrix and upper left, keep matrix
+        formula dimension. */
+    void ResetResult();
 };
 
 
diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx
index 32a266d..4582c96 100644
--- a/sc/inc/tokenarray.hxx
+++ b/sc/inc/tokenarray.hxx
@@ -21,7 +21,6 @@
 #define SC_TOKENARRAY_HXX
 
 #include "formula/token.hxx"
-#include "scmatrix.hxx"
 #include <tools/solar.h>
 #include "scdllapi.h"
 #include "types.hxx"
diff --git a/sc/inc/types.hxx b/sc/inc/types.hxx
index 629ab72..487afcd 100644
--- a/sc/inc/types.hxx
+++ b/sc/inc/types.hxx
@@ -20,6 +20,14 @@ typedef ::boost::intrusive_ptr<const ScMatrix>  ScConstMatrixRef;
 class ScToken;
 typedef ::boost::intrusive_ptr<ScToken> ScTokenRef;
 
+typedef sal_uInt8 ScMatValType;
+const ScMatValType SC_MATVAL_VALUE     = 0x00;
+const ScMatValType SC_MATVAL_BOOLEAN   = 0x01;
+const ScMatValType SC_MATVAL_STRING    = 0x02;
+const ScMatValType SC_MATVAL_EMPTY     = SC_MATVAL_STRING | 0x04; // STRING plus flag
+const ScMatValType SC_MATVAL_EMPTYPATH = SC_MATVAL_EMPTY | 0x08;  // EMPTY plus flag
+const ScMatValType SC_MATVAL_NONVALUE  = SC_MATVAL_EMPTYPATH;     // mask of all non-value bits
+
 struct ScFormulaCellGroup;
 typedef ::boost::intrusive_ptr<ScFormulaCellGroup> ScFormulaCellGroupRef;
 
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index ae20e44..abe2806 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -42,6 +42,7 @@
 #include "formulagroup.hxx"
 #include "listenercontext.hxx"
 #include "mtvcellfunc.hxx"
+#include "scmatrix.hxx"
 
 #include <math.h>
 
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 60696df..02cb39b 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -37,6 +37,7 @@
 #include "globstr.hrc"
 #include "editutil.hxx"
 #include "cellvalue.hxx"
+#include "scmatrix.hxx"
 
 #include "tools/fract.hxx"
 #include "editeng/editobj.hxx"
diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx
index f59c119..9211db8 100644
--- a/sc/source/core/data/documen4.cxx
+++ b/sc/source/core/data/documen4.cxx
@@ -43,6 +43,7 @@
 #include "attrib.hxx"
 #include "formulacell.hxx"
 #include "tokenarray.hxx"
+#include "scmatrix.hxx"
 
 using namespace formula;
 
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 02c8952..9b1ea3d 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -46,6 +46,7 @@
 #include "conditio.hxx"
 #include "globalnames.hxx"
 #include "cellvalue.hxx"
+#include "scmatrix.hxx"
 
 #include <vector>
 
diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx
index f910083..175c3db 100644
--- a/sc/source/core/data/validat.cxx
+++ b/sc/source/core/data/validat.cxx
@@ -17,7 +17,8 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include "scitems.hxx"
+#include "validat.hxx"
+
 #include <sfx2/app.hxx>
 #include <sfx2/docfile.hxx>
 #include <sfx2/objsh.hxx>
@@ -31,7 +32,7 @@
 #include <vcl/msgbox.hxx>
 #include <rtl/math.hxx>
 
-#include "validat.hxx"
+#include "scitems.hxx"
 #include "document.hxx"
 #include "formulacell.hxx"
 #include "patattr.hxx"
@@ -43,6 +44,7 @@
 #include "dociter.hxx"
 #include "editutil.hxx"
 #include "tokenarray.hxx"
+#include "scmatrix.hxx"
 
 #include <math.h>
 #include <memory>
diff --git a/sc/source/core/inc/ddelink.hxx b/sc/source/core/inc/ddelink.hxx
index 967daae..f6ceba3 100644
--- a/sc/source/core/inc/ddelink.hxx
+++ b/sc/source/core/inc/ddelink.hxx
@@ -23,7 +23,7 @@
 #include "address.hxx"
 #include <sfx2/lnkbase.hxx>
 #include <svl/broadcast.hxx>
-#include "scmatrix.hxx"
+#include "types.hxx"
 
 class ScDocument;
 class ScMultipleReadHeader;
@@ -67,11 +67,11 @@ public:
 
                     // for interpreter:
 
-    const ScMatrix* GetResult() const           { return pResult.get(); }
-    void            SetResult( ScMatrixRef pRes ) { pResult = pRes; }
+    const ScMatrix* GetResult() const;
+    void            SetResult( const ScMatrixRef& pRes );
 
                     // XML and Excel import after NewData()
-    ScMatrixRef     GetModifiableResult()   { return pResult; }
+    ScMatrixRef     GetModifiableResult();
 
     const String&   GetAppl() const     { return aAppl; }
     const String&   GetTopic() const    { return aTopic; }
diff --git a/sc/source/core/inc/doubleref.hxx b/sc/source/core/inc/doubleref.hxx
index 1782f44..5de9c97 100644
--- a/sc/source/core/inc/doubleref.hxx
+++ b/sc/source/core/inc/doubleref.hxx
@@ -21,7 +21,7 @@
 #define SC_DOUBLEREF_HXX
 
 #include "address.hxx"
-#include "scmatrix.hxx"
+#include "types.hxx"
 
 class ScDocument;
 struct ScDBQueryParamBase;
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index 75947d6..3792383 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -26,7 +26,7 @@
 #include "formula/errorcodes.hxx"
 #include "formula/tokenarray.hxx"
 #include "scdll.hxx"
-#include "scmatrix.hxx"
+#include "types.hxx"
 #include "externalrefmgr.hxx"
 #include "calcconfig.hxx"
 #include "token.hxx"
diff --git a/sc/source/core/inc/jumpmatrix.hxx b/sc/source/core/inc/jumpmatrix.hxx
index ccd0b66..30391f9 100644
--- a/sc/source/core/inc/jumpmatrix.hxx
+++ b/sc/source/core/inc/jumpmatrix.hxx
@@ -24,7 +24,8 @@
 #include "formula/errorcodes.hxx"
 #include <tools/solar.h>
 #include <vector>
-#include "scmatrix.hxx"
+#include "types.hxx"
+#include "address.hxx"
 
 typedef ::std::vector< formula::FormulaToken*> ScTokenVec;
 
@@ -55,159 +56,35 @@ struct ScJumpMatrixEntry
 
 class ScJumpMatrix
 {
-            ScJumpMatrixEntry*  pJump;      // the jumps
-            ScMatrixRef         pMat;       // the results
-            ScTokenVec*         pParams;    // parameter stack
-            SCSIZE              nCols;
-            SCSIZE              nRows;
-            SCSIZE              nCurCol;
-            SCSIZE              nCurRow;
-            SCSIZE              nResMatCols;
-            SCSIZE              nResMatRows;
-            bool                bStarted;
+    ScJumpMatrixEntry*  pJump;      // the jumps
+    ScMatrixRef         pMat;       // the results
+    ScTokenVec*         pParams;    // parameter stack
+    SCSIZE              nCols;
+    SCSIZE              nRows;
+    SCSIZE              nCurCol;
+    SCSIZE              nCurRow;
+    SCSIZE              nResMatCols;
+    SCSIZE              nResMatRows;
+    bool                bStarted;
 
-                                // not implemented, prevent usage
-                                ScJumpMatrix( const ScJumpMatrix& );
-            ScJumpMatrix&       operator=( const ScJumpMatrix& );
+    // not implemented, prevent usage
+    ScJumpMatrix( const ScJumpMatrix& );
+    ScJumpMatrix& operator=( const ScJumpMatrix& );
 
 public:
-                                ScJumpMatrix( SCSIZE nColsP, SCSIZE nRowsP )
-                                        : pJump( new ScJumpMatrixEntry[ nColsP * nRowsP ] )
-                                        , pMat( new ScMatrix( nColsP, nRowsP) )
-                                        , pParams( NULL )
-                                        , nCols( nColsP )
-                                        , nRows( nRowsP )
-                                        , nCurCol( 0 )
-                                        , nCurRow( 0 )
-                                        , nResMatCols( nColsP )
-                                        , nResMatRows( nRowsP )
-                                        , bStarted( false )
-                                    {
-                                        // Initialize result matrix in case of
-                                        // a premature end of the interpreter
-                                        // due to errors.
-                                        pMat->FillDouble( CreateDoubleError(
-                                                NOTAVAILABLE), 0, 0, nCols-1,
-                                                nRows-1);
-                                        /*! pJump not initialized */
-                                    }
-                                ~ScJumpMatrix()
-                                    {
-                                        if ( pParams )
-                                        {
-                                            for ( ScTokenVec::iterator i =
-                                                    pParams->begin(); i !=
-                                                    pParams->end(); ++i )
-                                            {
-                                                (*i)->DecRef();
-                                            }
-                                            delete pParams;
-                                        }
-                                        delete [] pJump;
-                                    }
-            void                GetDimensions( SCSIZE& rCols, SCSIZE& rRows ) const
-                                    {
-                                        rCols = nCols;
-                                        rRows = nRows;
-                                    }
-            void                SetJump( SCSIZE nCol, SCSIZE nRow, double fBool,
-                                            short nStart, short nNext,
-                                            short nStop = SHRT_MAX )
-                                    {
-                                        pJump[ (sal_uLong)nCol * nRows + nRow ].
-                                            SetJump( fBool, nStart, nNext, nStop);
-                                    }
-            void                GetJump( SCSIZE nCol, SCSIZE nRow, double& rBool,
-                                            short& rStart, short& rNext,
-                                            short& rStop ) const
-                                    {
-                                        if (nCols == 1 && nRows == 1)
-                                        {
-                                            nCol = 0;
-                                            nRow = 0;
-                                        }
-                                        else if (nCols == 1 && nRow < nRows)
-                                            nCol = 0;
-                                        else if (nRows == 1 && nCol < nCols)
-                                            nRow = 0;
-                                        else if (nCols <= nCol || nRows <= nRow)
-                                        {
-                                            OSL_FAIL("ScJumpMatrix::GetJump: dimension error");
-                                            nCol = 0;
-                                            nRow = 0;
-                                        }
-                                        pJump[ (sal_uLong)nCol * nRows + nRow ].
-                                            GetJump( rBool, rStart, rNext, rStop);
-                                    }
-            void                SetAllJumps( double fBool,
-                                            short nStart, short nNext,
-                                            short nStop = SHRT_MAX )
-                                    {
-                                        sal_uLong n = (sal_uLong)nCols * nRows;
-                                        for ( sal_uLong j=0; j<n; ++j )
-                                        {
-                                            pJump[ j ].SetJump( fBool, nStart,
-                                                    nNext, nStop);
-                                        }
-                                    }
-            void                SetJumpParameters( ScTokenVec* p )
-                                    { pParams = p; }
-            const ScTokenVec*   GetJumpParameters() const { return pParams; }
-            ScMatrix*           GetResultMatrix() const { return pMat.get(); }
-            void                GetPos( SCSIZE& rCol, SCSIZE& rRow ) const
-                                    {
-                                        rCol = nCurCol;
-                                        rRow = nCurRow;
-                                    }
-            bool                Next( SCSIZE& rCol, SCSIZE& rRow )
-                                    {
-                                        if ( !bStarted )
-                                        {
-                                            bStarted = true;
-                                            nCurCol = nCurRow = 0;
-                                        }
-                                        else
-                                        {
-                                            if ( ++nCurRow >= nResMatRows )
-                                            {
-                                                nCurRow = 0;
-                                                ++nCurCol;
-                                            }
-                                        }
-                                        GetPos( rCol, rRow );
-                                        return nCurCol < nResMatCols;
-                                    }
-            void                GetResMatDimensions( SCSIZE& rCols, SCSIZE& rRows )
-                                    {
-                                        rCols = nResMatCols;
-                                        rRows = nResMatRows;
-                                    }
-            void                SetNewResMat( SCSIZE nNewCols, SCSIZE nNewRows )
-                                    {
-                                        if ( nNewCols > nResMatCols || nNewRows > nResMatRows )
-                                        {
-                                            pMat = pMat->CloneAndExtend(nNewCols, nNewRows);
-                                            if ( nResMatCols < nNewCols )
-                                            {
-                                                pMat->FillDouble( CreateDoubleError(
-                                                    NOTAVAILABLE), nResMatCols, 0, nNewCols-1,
-                                                    nResMatRows-1);
-                                            }
-                                            if ( nResMatRows < nNewRows )
-                                            {
-                                                pMat->FillDouble( CreateDoubleError(
-                                                    NOTAVAILABLE), 0, nResMatRows, nNewCols-1,
-                                                    nNewRows-1);
-                                            }
-                                            if ( nRows == 1 && nCurCol != 0 )
-                                            {
-                                                nCurCol = 0;
-                                                nCurRow = nResMatRows - 1;
-                                            }
-                                            nResMatCols = nNewCols;
-                                            nResMatRows = nNewRows;
-                                        }
-                                    }
+    ScJumpMatrix( SCSIZE nColsP, SCSIZE nRowsP );
+    ~ScJumpMatrix();
+    void GetDimensions( SCSIZE& rCols, SCSIZE& rRows ) const;
+    void SetJump( SCSIZE nCol, SCSIZE nRow, double fBool, short nStart, short nNext, short nStop = SHRT_MAX );
+    void GetJump( SCSIZE nCol, SCSIZE nRow, double& rBool, short& rStart, short& rNext, short& rStop ) const;
+    void SetAllJumps( double fBool, short nStart, short nNext, short nStop = SHRT_MAX );
+    void SetJumpParameters( ScTokenVec* p );
+    const ScTokenVec* GetJumpParameters() const;
+    ScMatrix* GetResultMatrix() const;
+    void GetPos( SCSIZE& rCol, SCSIZE& rRow ) const;
+    bool Next( SCSIZE& rCol, SCSIZE& rRow );
+    void GetResMatDimensions( SCSIZE& rCols, SCSIZE& rRows );
+    void SetNewResMat( SCSIZE nNewCols, SCSIZE nNewRows );
 };
 
 #endif // SC_JUMPMATRIX_HXX
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index d5c5401..20ab937 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -1700,9 +1700,9 @@ void ScUnoAddInCall::SetResult( const uno::Any& rNewRes )
     }
 }
 
-
-
-//------------------------------------------------------------------------
-
+ScMatrixRef ScUnoAddInCall::GetMatrix() const
+{
+    return xMatrix;
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 3d6806c..9b4c4d1 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -63,6 +63,7 @@
 #include "tokenuno.hxx"
 #include "formulaparserpool.hxx"
 #include "tokenarray.hxx"
+#include "scmatrix.hxx"
 
 using namespace formula;
 using namespace ::com::sun::star;
diff --git a/sc/source/core/tool/ddelink.cxx b/sc/source/core/tool/ddelink.cxx
index bd6eb92..76e7616 100644
--- a/sc/source/core/tool/ddelink.cxx
+++ b/sc/source/core/tool/ddelink.cxx
@@ -239,6 +239,21 @@ void ScDdeLink::ListenersGone()
     bIsInUpdate = bWas;
 }
 
+const ScMatrix* ScDdeLink::GetResult() const
+{
+    return pResult.get();
+}
+
+void ScDdeLink::SetResult( const ScMatrixRef& pRes )
+{
+    pResult = pRes;
+}
+
+ScMatrixRef ScDdeLink::GetModifiableResult()
+{
+    return pResult;
+}
+
 void ScDdeLink::TryUpdate()
 {
     if (bIsInUpdate)
diff --git a/sc/source/core/tool/doubleref.cxx b/sc/source/core/tool/doubleref.cxx
index f7d873c..5b0920a 100644
--- a/sc/source/core/tool/doubleref.cxx
+++ b/sc/source/core/tool/doubleref.cxx
@@ -24,6 +24,7 @@
 #include "queryparam.hxx"
 #include "queryentry.hxx"
 #include "globstr.hrc"
+#include "scmatrix.hxx"
 
 #include <memory>
 #include <vector>
diff --git a/sc/source/core/tool/formulagroup.cxx b/sc/source/core/tool/formulagroup.cxx
index f9d251b..4a04f79 100644
--- a/sc/source/core/tool/formulagroup.cxx
+++ b/sc/source/core/tool/formulagroup.cxx
@@ -14,6 +14,8 @@
 #include "tokenarray.hxx"
 #include "compiler.hxx"
 #include "interpre.hxx"
+#include "scmatrix.hxx"
+
 #include "formula/vectortoken.hxx"
 
 namespace sc {
diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx
index a106e5f..a20963b 100644
--- a/sc/source/core/tool/formularesult.cxx
+++ b/sc/source/core/tool/formularesult.cxx
@@ -11,6 +11,7 @@
  */
 
 #include "formularesult.hxx"
+#include "scmatrix.hxx"
 
 ScFormulaResult::ScFormulaResult() :
     mpToken(NULL), mnError(0), mbToken(true),
diff --git a/sc/source/core/tool/jumpmatrix.cxx b/sc/source/core/tool/jumpmatrix.cxx
new file mode 100644
index 0000000..6a8b4a7
--- /dev/null
+++ b/sc/source/core/tool/jumpmatrix.cxx
@@ -0,0 +1,173 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "jumpmatrix.hxx"
+#include "scmatrix.hxx"
+
+ScJumpMatrix::ScJumpMatrix(SCSIZE nColsP, SCSIZE nRowsP)
+    : pJump(new ScJumpMatrixEntry[nColsP * nRowsP])
+    , pMat(new ScMatrix(nColsP, nRowsP))
+    , pParams(NULL)
+    , nCols(nColsP)
+    , nRows(nRowsP)
+    , nCurCol(0)
+    , nCurRow(0)
+    , nResMatCols(nColsP)
+    , nResMatRows(nRowsP)
+    , bStarted(false)
+{
+    // Initialize result matrix in case of
+    // a premature end of the interpreter
+    // due to errors.
+    pMat->FillDouble(CreateDoubleError(NOTAVAILABLE), 0, 0, nCols - 1, nRows - 1);
+    /*! pJump not initialized */
+}
+
+ScJumpMatrix::~ScJumpMatrix()
+{
+    if (pParams)
+    {
+        for (ScTokenVec::iterator i =
+             pParams->begin(); i !=
+                 pParams->end(); ++i)
+        {
+            (*i)->DecRef();
+        }
+        delete pParams;
+    }
+    delete[] pJump;
+}
+
+void ScJumpMatrix::GetDimensions(SCSIZE& rCols, SCSIZE& rRows) const
+{
+    rCols = nCols;
+    rRows = nRows;
+}
+
+void ScJumpMatrix::SetJump(SCSIZE nCol, SCSIZE nRow, double fBool,
+                           short nStart, short nNext, short nStop)
+{
+    pJump[(sal_uLong)nCol * nRows + nRow].SetJump(fBool, nStart, nNext, nStop);
+}
+
+void ScJumpMatrix::GetJump(
+    SCSIZE nCol, SCSIZE nRow, double& rBool, short& rStart, short& rNext, short& rStop) const
+{
+    if (nCols == 1 && nRows == 1)
+    {
+        nCol = 0;
+        nRow = 0;
+    }
+    else if (nCols == 1 && nRow < nRows) nCol = 0;
+    else if (nRows == 1 && nCol < nCols) nRow = 0;
+    else if (nCols <= nCol || nRows <= nRow)
+    {
+        OSL_FAIL("ScJumpMatrix::GetJump: dimension error");
+        nCol = 0;
+        nRow = 0;
+    }
+    pJump[(sal_uLong)nCol * nRows + nRow].
+        GetJump(rBool, rStart, rNext, rStop);
+}
+
+void ScJumpMatrix::SetAllJumps(double fBool, short nStart, short nNext, short nStop)
+{
+    sal_uLong n = (sal_uLong)nCols * nRows;
+    for (sal_uLong j = 0; j < n; ++j)
+    {
+        pJump[j].SetJump(fBool, nStart,
+                         nNext, nStop);
+    }
+}
+
+void ScJumpMatrix::SetJumpParameters(ScTokenVec* p)
+{
+    pParams = p;
+}
+
+const ScTokenVec* ScJumpMatrix::GetJumpParameters() const
+{
+    return pParams;
+}
+
+ScMatrix* ScJumpMatrix::GetResultMatrix() const
+{
+    return pMat.get();
+}
+
+void ScJumpMatrix::GetPos(SCSIZE& rCol, SCSIZE& rRow) const
+{
+    rCol = nCurCol;
+    rRow = nCurRow;
+}
+
+bool ScJumpMatrix::Next(SCSIZE& rCol, SCSIZE& rRow)
+{
+    if (!bStarted)
+    {
+        bStarted = true;
+        nCurCol = nCurRow = 0;
+    }
+    else
+    {
+        if (++nCurRow >= nResMatRows)
+        {
+            nCurRow = 0;
+            ++nCurCol;
+        }
+    }
+    GetPos(rCol, rRow);
+    return nCurCol < nResMatCols;
+}
+
+void ScJumpMatrix::GetResMatDimensions(SCSIZE& rCols, SCSIZE& rRows)
+{
+    rCols = nResMatCols;
+    rRows = nResMatRows;
+}
+
+void ScJumpMatrix::SetNewResMat(SCSIZE nNewCols, SCSIZE nNewRows)
+{
+    if (nNewCols > nResMatCols || nNewRows > nResMatRows)
+    {
+        pMat = pMat->CloneAndExtend(nNewCols, nNewRows);
+        if (nResMatCols < nNewCols)
+        {
+            pMat->FillDouble(CreateDoubleError(
+                                 NOTAVAILABLE), nResMatCols, 0, nNewCols - 1,
+                             nResMatRows - 1);
+        }
+        if (nResMatRows < nNewRows)
+        {
+            pMat->FillDouble(CreateDoubleError(
+                                 NOTAVAILABLE), 0, nResMatRows, nNewCols - 1,
+                             nNewRows - 1);
+        }
+        if (nRows == 1 && nCurCol != 0)
+        {
+            nCurCol = 0;
+            nCurRow = nResMatRows - 1;
+        }
+        nResMatCols = nNewCols;
+        nResMatRows = nNewRows;
+    }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx
index 826ea3e..b202432 100644
--- a/sc/source/core/tool/queryparam.cxx
+++ b/sc/source/core/tool/queryparam.cxx
@@ -19,6 +19,7 @@
 
 #include "queryparam.hxx"
 #include "queryentry.hxx"
+#include "scmatrix.hxx"
 
 namespace {
 
diff --git a/sc/source/core/tool/rangenam.cxx b/sc/source/core/tool/rangenam.cxx
index b833fec..4d81099 100644
--- a/sc/source/core/tool/rangenam.cxx
+++ b/sc/source/core/tool/rangenam.cxx
@@ -34,6 +34,8 @@
 #include "refupdat.hxx"
 #include "document.hxx"
 
+#include "formula/errorcodes.hxx"
+
 using namespace formula;
 using ::std::pair;
 using ::std::unary_function;
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 3dff6a9..55c051d 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -37,6 +37,7 @@
 #include "rangeseq.hxx"
 #include "externalrefmgr.hxx"
 #include "document.hxx"
+#include "scmatrix.hxx"
 
 using ::std::vector;
 
@@ -795,6 +796,11 @@ bool ScRefListToken::operator==( const FormulaToken& r ) const
     return FormulaToken::operator==( r ) && &aRefList == static_cast<const ScToken&>(r).GetRefList();
 }
 
+ScMatrixToken::ScMatrixToken( const ScMatrixRef& p ) :
+    ScToken(formula::svMatrix), pMatrix(p) {}
+
+ScMatrixToken::ScMatrixToken( const ScMatrixToken& r ) :
+    ScToken(r), pMatrix(r.pMatrix) {}
 
 const ScMatrix* ScMatrixToken::GetMatrix() const        { return pMatrix.get(); }
 ScMatrix*       ScMatrixToken::GetMatrix()              { return pMatrix.get(); }
@@ -1031,6 +1037,11 @@ bool ScEmptyCellToken::operator==( const FormulaToken& r ) const
         bDisplayedAsString == static_cast< const ScEmptyCellToken & >(r).IsDisplayedAsString();
 }
 
+ScMatrixCellResultToken::ScMatrixCellResultToken( const ScConstMatrixRef& pMat, formula::FormulaToken* pUL ) :
+    ScToken(formula::svMatrixCell), xMatrix(pMat), xUpperLeft(pUL) {}
+
+ScMatrixCellResultToken::ScMatrixCellResultToken( const ScMatrixCellResultToken& r ) :
+    ScToken(r), xMatrix(r.xMatrix), xUpperLeft(r.xUpperLeft) {}
 
 double          ScMatrixCellResultToken::GetDouble() const  { return xUpperLeft->GetDouble(); }
 const String &  ScMatrixCellResultToken::GetString() const  { return xUpperLeft->GetString(); }
@@ -1041,6 +1052,7 @@ ScMatrix* ScMatrixCellResultToken::GetMatrix()
 {
     return const_cast<ScMatrix*>(xMatrix.get());
 }
+
 bool ScMatrixCellResultToken::operator==( const FormulaToken& r ) const
 {
     return FormulaToken::operator==( r ) &&
@@ -1048,6 +1060,27 @@ bool ScMatrixCellResultToken::operator==( const FormulaToken& r ) const
         xMatrix == static_cast<const ScMatrixCellResultToken &>(r).xMatrix;
 }
 
+void ScMatrixCellResultToken::Assign( const ScMatrixCellResultToken & r )
+{
+    xMatrix = r.xMatrix;
+    xUpperLeft = r.xUpperLeft;
+}
+
+ScMatrixFormulaCellToken::ScMatrixFormulaCellToken(
+    SCCOL nC, SCROW nR, const ScConstMatrixRef& pMat, formula::FormulaToken* pUL ) :
+    ScMatrixCellResultToken(pMat, pUL), nRows(nR), nCols(nC) {}
+
+ScMatrixFormulaCellToken::ScMatrixFormulaCellToken( SCCOL nC, SCROW nR ) :
+    ScMatrixCellResultToken(NULL, NULL), nRows(nR), nCols(nC) {}
+
+ScMatrixFormulaCellToken::ScMatrixFormulaCellToken( const ScMatrixFormulaCellToken& r ) :
+    ScMatrixCellResultToken(r), nRows(r.nRows), nCols(r.nCols)
+{
+    // xUpperLeft is modifiable through
+    // SetUpperLeftDouble(), so clone it.
+    if (xUpperLeft)
+        xUpperLeft = xUpperLeft->Clone();
+}
 
 bool ScMatrixFormulaCellToken::operator==( const FormulaToken& r ) const
 {
@@ -1077,6 +1110,7 @@ void ScMatrixFormulaCellToken::Assign( const formula::FormulaToken& r )
         }
     }
 }
+
 void ScMatrixFormulaCellToken::SetUpperLeftDouble( double f )
 {
     switch (GetUpperLeftType())
@@ -1098,6 +1132,12 @@ void ScMatrixFormulaCellToken::SetUpperLeftDouble( double f )
     }
 }
 
+void ScMatrixFormulaCellToken::ResetResult()
+{
+    xMatrix = NULL;
+    xUpperLeft = NULL;
+}
+
 
 double ScHybridCellToken::GetDouble() const { return mfDouble; }
 const String& ScHybridCellToken::GetString() const { return maString; }
diff --git a/sc/source/filter/excel/excform.cxx b/sc/source/filter/excel/excform.cxx
index 10b95f7..269c66f 100644
--- a/sc/source/filter/excel/excform.cxx
+++ b/sc/source/filter/excel/excform.cxx
@@ -24,6 +24,8 @@
 #include "document.hxx"
 #include "rangenam.hxx"
 #include "global.hxx"
+#include "scmatrix.hxx"
+
 #include "formula/errorcodes.hxx"
 
 #include "imp_op.hxx"
diff --git a/sc/source/filter/excel/xeformula.cxx b/sc/source/filter/excel/xeformula.cxx
index 5265bd1..7065d10 100644
--- a/sc/source/filter/excel/xeformula.cxx
+++ b/sc/source/filter/excel/xeformula.cxx
@@ -27,6 +27,7 @@
 #include "rangelst.hxx"
 #include "token.hxx"
 #include "tokenarray.hxx"
+#include "scmatrix.hxx"
 #include "xeformula.hxx"
 #include "xehelper.hxx"
 #include "xelink.hxx"
diff --git a/sc/source/filter/excel/xehelper.cxx b/sc/source/filter/excel/xehelper.cxx
index a13b7fe..2a2e2dc 100644
--- a/sc/source/filter/excel/xehelper.cxx
+++ b/sc/source/filter/excel/xehelper.cxx
@@ -40,6 +40,7 @@
 #include "formulacell.hxx"
 #include "editutil.hxx"
 #include "patattr.hxx"
+#include "scmatrix.hxx"
 #include "xestyle.hxx"
 #include "fprogressbar.hxx"
 #include "xltracer.hxx"
diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx
index c002ae9..824f4c4 100644
--- a/sc/source/filter/excel/xihelper.cxx
+++ b/sc/source/filter/excel/xihelper.cxx
@@ -33,6 +33,7 @@
 #include "xistyle.hxx"
 #include "excform.hxx"
 #include "stringutil.hxx"
+#include "scmatrix.hxx"
 
 // Excel->Calc cell address/range conversion ==================================
 
@@ -798,7 +799,7 @@ XclImpCachedValue::XclImpCachedValue( XclImpStream& rStrm ) :
             rStrm >> mfValue;
         break;
         case EXC_CACHEDVAL_STRING:
-            mxStr.reset( new String( rStrm.ReadUniString() ) );
+            maStr = rStrm.ReadUniString();
         break;
         case EXC_CACHEDVAL_BOOL:
         case EXC_CACHEDVAL_ERROR:
@@ -822,6 +823,11 @@ XclImpCachedValue::~XclImpCachedValue()
 {
 }
 
+const OUString& XclImpCachedValue::GetString() const
+{
+    return maStr;
+}
+
 sal_uInt16 XclImpCachedValue::GetScError() const
 {
     return (mnType == EXC_CACHEDVAL_ERROR) ? XclTools::GetScErrorCode( mnBoolErr ) : 0;
diff --git a/sc/source/filter/excel/xilink.cxx b/sc/source/filter/excel/xilink.cxx
index a89d366..7ccc4ae 100644
--- a/sc/source/filter/excel/xilink.cxx
+++ b/sc/source/filter/excel/xilink.cxx
@@ -28,6 +28,7 @@
 #include "excform.hxx"
 #include "tokenarray.hxx"
 #include "externalrefmgr.hxx"
+#include "scmatrix.hxx"
 
 #include <vector>
 #include <boost/ptr_container/ptr_vector.hpp>
@@ -599,7 +600,7 @@ void XclImpSupbookTab::LoadCachedValues(ScExternalRefCache::TableTypeRef pCacheT
             break;
             case EXC_CACHEDVAL_STRING:
             {
-                const String& rStr = pCrn->GetString();
+                const OUString& rStr = pCrn->GetString();
                 ScExternalRefCache::TokenRef pToken(new formula::FormulaStringToken(rStr));
                 pCacheTable->setCell(rAddr.mnCol, rAddr.mnRow, pToken, 0, false);
             }
diff --git a/sc/source/filter/inc/xihelper.hxx b/sc/source/filter/inc/xihelper.hxx
index 52f7d25..ed6426d 100644
--- a/sc/source/filter/inc/xihelper.hxx
+++ b/sc/source/filter/inc/xihelper.hxx
@@ -24,7 +24,7 @@
 #include <boost/noncopyable.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
-#include "scmatrix.hxx"
+#include "types.hxx"
 #include "xladdress.hxx"
 #include "xiroot.hxx"
 #include "xistring.hxx"
@@ -301,7 +301,7 @@ public:
     /** Returns the type of the cached value (EXC_CACHEDVAL_*). */
     inline sal_uInt8    GetType() const     { return mnType; }
     /** Returns the cached string value, if this value is a string, else an empty string. */
-    inline const String& GetString() const  { return mxStr.get() ? *mxStr : EMPTY_STRING; }
+    const OUString& GetString() const;
     /** Returns the cached number, if this value has number type, else 0.0. */
     inline double       GetValue() const    { return mfValue; }
     /** Returns the cached Boolean value, if this value has Boolean type, else false. */
@@ -312,10 +312,9 @@ public:
     sal_uInt16              GetScError() const;
 
 protected:
-    typedef ::std::auto_ptr< String >               StringPtr;
     typedef ::std::auto_ptr< const ScTokenArray >   ScTokenArrayPtr;
 
-    StringPtr           mxStr;      /// Cached value is a string.
+    OUString            maStr;      /// Cached value is a string.
     double              mfValue;    /// Cached value is a double.
     ScTokenArrayPtr     mxTokArr;   /// Cached value is a formula or error code or Boolean.
     sal_uInt8           mnBoolErr;  /// Boolean value or Excel error code.
diff --git a/sc/source/filter/inc/xilink.hxx b/sc/source/filter/inc/xilink.hxx
index 09b0098..985e6ee 100644
--- a/sc/source/filter/inc/xilink.hxx
+++ b/sc/source/filter/inc/xilink.hxx
@@ -23,7 +23,7 @@
 #include <map>
 #include "xllink.hxx"
 #include "xiroot.hxx"
-#include "scmatrix.hxx"
+#include "types.hxx"
 
 /* ============================================================================
 Classes for import of different kinds of internal/external references.
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 4ab9d98..445766e 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -50,6 +50,7 @@
 #include "editattributemap.hxx"
 #include "stringutil.hxx"
 #include "tokenarray.hxx"
+#include "scmatrix.hxx"
 
 #include <xmloff/xmltkmap.hxx>
 #include <xmloff/xmltoken.hxx>
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index b6f847b..87a9b16 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -51,6 +51,7 @@
 #include "unotools/localfilehelper.hxx"
 #include "vcl/msgbox.hxx"
 #include "stringutil.hxx"
+#include "scmatrix.hxx"
 
 #include <memory>
 #include <algorithm>
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 81e4953..6ec562d 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -37,6 +37,7 @@
 #include "docsh.hxx"
 #include "cellvalue.hxx"
 #include "tokenarray.hxx"
+#include "scmatrix.hxx"
 
 #include "formula/opcode.hxx"
 
diff --git a/sc/source/ui/unoobj/linkuno.cxx b/sc/source/ui/unoobj/linkuno.cxx
index 897d4aa..0531ff9 100644
--- a/sc/source/ui/unoobj/linkuno.cxx
+++ b/sc/source/ui/unoobj/linkuno.cxx
@@ -32,6 +32,7 @@
 #include "unonames.hxx"
 #include "rangeseq.hxx"
 #include "token.hxx"
+#include "scmatrix.hxx"
 
 #include <vector>
 #include <climits>
commit 83f77ab0661df992f241e5f9ecb1aa8f8eaeafec
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date:   Mon Jul 1 15:47:41 2013 -0400

    Rework SUMPRODUCT to reduce the number of block position lookups.
    
    Change-Id: I22b843142b76df1c51597a8138b1674286f78792

diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index d6ac279..ccb989f 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -119,6 +119,8 @@ class SC_DLLPUBLIC ScMatrix
     ScMatrix& operator=( const ScMatrix&);
 
 public:
+    enum Op { Add, Sub, Mul, Div };
+
     /**
      * When adding all numerical matrix elements for a scalar result such as
      * summation, the interpreter wants to separate the first non-zero value
@@ -352,8 +354,8 @@ public:
     double GetMaxValue( bool bTextAsZero ) const;
     double GetMinValue( bool bTextAsZero ) const;
 
-    // All other matrix functions  MatMult, MInv, ...  are in ScInterpreter
-    // to be numerically safe.
+    void GetDoubleArray( std::vector<double>& rArray ) const;
+    void MergeDoubleArray( std::vector<double>& rArray, Op eOp ) const;
 
 #if DEBUG_MATRIX
     void Dump() const;
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index c6fc44a..79a038d 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1595,6 +1595,49 @@ void ScInterpreter::ScPow()
         PushDouble(pow(fVal1,fVal2));
 }
 
+namespace {
+
+bool mergeArray( std::vector<double>& rRes, const std::vector<double>& rOther )
+{
+    if (rRes.size() != rOther.size())
+        return false;
+
+    double fNan;
+    rtl::math::setNan(&fNan);
+
+    std::vector<double>::iterator it = rRes.begin(), itEnd = rRes.end();
+    std::vector<double>::const_iterator itOther = rOther.begin();
+    for (; it != itEnd; ++it, ++itOther)
+    {
+        if (rtl::math::isNan(*it) || rtl::math::isNan(*itOther))
+        {
+            *it = fNan;
+            continue;
+        }
+
+        *it *= *itOther;
+    }
+
+    return true;
+}
+
+class SumValues : std::unary_function<double, void>
+{
+    double mfSum;
+public:
+    SumValues() : mfSum(0.0) {}
+
+    void operator() (double f)
+    {
+        if (!rtl::math::isNan(f))
+            mfSum += f;
+    }
+
+    double getValue() const { return mfSum; }
+};
+
+}
+
 void ScInterpreter::ScSumProduct()
 {
     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScSumProduct" );
@@ -1602,49 +1645,40 @@ void ScInterpreter::ScSumProduct()
     if ( !MustHaveParamCount( nParamCount, 1, 30 ) )
         return;
 
-    ScMatrixRef pMat1 = NULL;
-    ScMatrixRef pMat2 = NULL;
-    ScMatrixRef pMat  = NULL;
-    pMat2 = GetMatrix();
-    if (!pMat2)
+    ScMatrixRef pMatLast;
+    ScMatrixRef pMat;
+
+    pMatLast = GetMatrix();
+    if (!pMatLast)
     {
         PushIllegalParameter();
         return;
     }
-    SCSIZE nC, nC1;
-    SCSIZE nR, nR1;
-    pMat2->GetDimensions(nC, nR);
-    pMat = pMat2;
-    for (sal_uInt16 i = 1; i < nParamCount; i++)
+
+    SCSIZE nC, nCLast, nR, nRLast;
+    pMatLast->GetDimensions(nCLast, nRLast);
+    std::vector<double> aResArray;
+    pMatLast->GetDoubleArray(aResArray);
+
+    for (sal_uInt16 i = 1; i < nParamCount; ++i)
     {
-        pMat1 = GetMatrix();
-        if (!pMat1)
+        pMat = GetMatrix();
+        if (!pMat)
         {
             PushIllegalParameter();
             return;
         }
-        pMat1->GetDimensions(nC1, nR1);
-        if (nC1 != nC || nR1 != nR)
-        {
-            PushNoValue();
-            return;
-        }
-        ScMatrixRef pResMat = lcl_MatrixCalculation<MatrixMul>(*pMat1, *pMat, this);
-        if (!pResMat)
+        pMat->GetDimensions(nC, nR);
+        if (nC != nCLast || nR != nRLast)
         {
             PushNoValue();
             return;
         }
-        else
-            pMat = pResMat;
-    }
-    double fSum = 0.0;
-    SCSIZE nCount = pMat->GetElementCount();
-    for (SCSIZE j = 0; j < nCount; j++)
-    {
-        if (!pMat->IsString(j))
-            fSum += pMat->GetDouble(j);
+
+        pMat->MergeDoubleArray(aResArray, ScMatrix::Mul);
     }
+
+    double fSum = std::for_each(aResArray.begin(), aResArray.end(), SumValues()).getValue();
     PushDouble(fSum);
 }
 
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index b0bef2e..ffc3382 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -225,6 +225,8 @@ public:
 
     double GetMaxValue( bool bTextAsZero ) const;
     double GetMinValue( bool bTextAsZero ) const;
+    void GetDoubleArray( std::vector<double>& rArray ) const;
+    void MergeDoubleArray( std::vector<double>& rArray, ScMatrix::Op eOp ) const;
 
 #if DEBUG_MATRIX
     void Dump() const;
@@ -1022,6 +1024,121 @@ public:
     }
 };
 
+class ToDoubleArray : std::unary_function<MatrixImplType::element_block_type, void>
+{
+    std::vector<double> maArray;
+    std::vector<double>::iterator miPos;
+    double mfNaN;
+public:
+    ToDoubleArray(size_t nSize) : maArray(nSize, 0.0), miPos(maArray.begin())
+    {
+        rtl::math::setNan(&mfNaN);
+    }
+
+    void operator() (const MatrixImplType::element_block_node_type& node)
+    {
+        using namespace mdds::mtv;
+
+        switch (node.type)
+        {
+            case mdds::mtm::element_numeric:
+            {
+                numeric_element_block::const_iterator it = numeric_element_block::begin(*node.data);
+                numeric_element_block::const_iterator itEnd = numeric_element_block::end(*node.data);
+                for (; it != itEnd; ++it, ++miPos)
+                    *miPos = *it;
+            }
+            break;
+            case mdds::mtm::element_boolean:
+            {
+                boolean_element_block::const_iterator it = boolean_element_block::begin(*node.data);
+                boolean_element_block::const_iterator itEnd = boolean_element_block::end(*node.data);
+                for (; it != itEnd; ++it, ++miPos)
+                    *miPos = *it ? 1.0 : 0.0;
+            }
+            break;
+            case mdds::mtm::element_string:
+            {
+                for (size_t i = 0; i < node.size; ++i, ++miPos)
+                    *miPos = mfNaN;
+            }
+            break;
+            default:
+                ;
+        }
+    }
+
+    void swap(std::vector<double>& rOther)
+    {
+        maArray.swap(rOther);
+    }
+};
+
+struct ArrayMul : public std::binary_function<double, double, double>
+{
+    double operator() (const double& lhs, const double& rhs) const
+    {
+        return lhs * rhs;
+    }
+};
+
+template<typename _Op>
+class MergeDoubleArrayFunc : std::unary_function<MatrixImplType::element_block_type, void>
+{
+    std::vector<double>& mrArray;
+    std::vector<double>::iterator miPos;
+    double mfNaN;
+public:
+    MergeDoubleArrayFunc(std::vector<double>& rArray) : mrArray(rArray), miPos(mrArray.begin())
+    {
+        rtl::math::setNan(&mfNaN);
+    }
+
+    void operator() (const MatrixImplType::element_block_node_type& node)
+    {
+        using namespace mdds::mtv;
+        static _Op op;
+
+        switch (node.type)
+        {
+            case mdds::mtm::element_numeric:
+            {
+                numeric_element_block::const_iterator it = numeric_element_block::begin(*node.data);
+                numeric_element_block::const_iterator itEnd = numeric_element_block::end(*node.data);
+                for (; it != itEnd; ++it, ++miPos)
+                {
+                    if (rtl::math::isNan(*miPos))
+                        continue;
+
+                    *miPos = op(*miPos, *it);
+                }
+            }
+            break;
+            case mdds::mtm::element_boolean:
+            {
+                boolean_element_block::const_iterator it = boolean_element_block::begin(*node.data);
+                boolean_element_block::const_iterator itEnd = boolean_element_block::end(*node.data);
+                for (; it != itEnd; ++it, ++miPos)
+                {
+                    if (rtl::math::isNan(*miPos))
+                        continue;
+
+                    *miPos = op(*miPos, *it ? 1.0 : 0.0);
+                }
+            }
+            break;
+            case mdds::mtm::element_string:
+            {
+                for (size_t i = 0; i < node.size; ++i, ++miPos)
+                    *miPos = mfNaN;
+            }
+            break;
+            default:
+                ;
+        }
+    }
+};
+
 }
 
 ScMatrix::IterateResult ScMatrixImpl::Sum(bool bTextAsZero) const
@@ -1067,6 +1184,34 @@ double ScMatrixImpl::GetMinValue( bool bTextAsZero ) const
     return aFunc.getValue();
 }
 
+void ScMatrixImpl::GetDoubleArray( std::vector<double>& rArray ) const
+{
+    MatrixImplType::size_pair_type aSize = maMat.size();
+    ToDoubleArray aFunc(aSize.row*aSize.column);
+    maMat.walk(aFunc);
+    aFunc.swap(rArray);
+}
+
+void ScMatrixImpl::MergeDoubleArray( std::vector<double>& rArray, ScMatrix::Op eOp ) const
+{
+    MatrixImplType::size_pair_type aSize = maMat.size();
+    size_t nSize = aSize.row*aSize.column;
+    if (nSize != rArray.size())
+        return;
+
+    switch (eOp)
+    {
+        case ScMatrix::Mul:
+        {
+            MergeDoubleArrayFunc<ArrayMul> aFunc(rArray);
+            maMat.walk(aFunc);
+        }
+        break;
+        default:
+            ;
+    }
+}
+
 #if DEBUG_MATRIX
 void ScMatrixImpl::Dump() const
 {
@@ -1419,6 +1564,16 @@ double ScMatrix::GetMinValue( bool bTextAsZero ) const
     return pImpl->GetMinValue(bTextAsZero);
 }
 
+void ScMatrix::GetDoubleArray( std::vector<double>& rArray ) const
+{
+    pImpl->GetDoubleArray(rArray);
+}
+
+void ScMatrix::MergeDoubleArray( std::vector<double>& rArray, Op eOp ) const
+{
+    pImpl->MergeDoubleArray(rArray, eOp);
+}
+
 #if DEBUG_MATRIX
 void ScMatrix::Dump() const
 {
@@ -1427,3 +1582,4 @@ void ScMatrix::Dump() const
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+


More information about the Libreoffice-commits mailing list