summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-10-19 13:55:53 -0400
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-10-19 13:57:40 -0400
commit75e6bcba872bc1fd7b4316ff219fb6545e9f542d (patch)
tree8c386142f15d10e4f7b7898674c0d9bcf58f62b4 /sc
parent8e8b43a03e77dd251876c1de0ac06eeeb09192cd (diff)
Construct and initialize result matrix in one step.
It's faster this way, than first constructing it then populating it in two separate steps. Change-Id: I61d30ed33a63dcf4c89b18d80ae4c3217cc43015
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/scmatrix.hxx6
-rw-r--r--sc/source/core/tool/interpr1.cxx10
-rw-r--r--sc/source/core/tool/scmatrix.cxx30
3 files changed, 30 insertions, 16 deletions
diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index b2a5d8d58aa7..f2508a658a08 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -202,6 +202,8 @@ public:
ScMatrix(SCSIZE nC, SCSIZE nR);
ScMatrix(SCSIZE nC, SCSIZE nR, double fInitVal);
+ ScMatrix( size_t nC, size_t nR, const std::vector<bool>& rInitVals );
+
/** Clone the matrix. */
ScMatrix* Clone() const;
@@ -351,8 +353,8 @@ public:
double GetMaxValue( bool bTextAsZero ) const;
double GetMinValue( bool bTextAsZero ) const;
- void CompareMatrix(
- ScMatrix& rResMat, sc::Compare& rComp, size_t nMatPos, sc::CompareOptions* pOptions = NULL ) const;
+ ScMatrixRef CompareMatrix(
+ sc::Compare& rComp, size_t nMatPos, sc::CompareOptions* pOptions = NULL ) const;
/**
* Convert the content of matrix into a linear array of numeric values.
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 69cfa10118a7..2cea9a2623bc 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1018,11 +1018,6 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
else if (aMat[0].mpMat || aMat[1].mpMat)
{
size_t i = ( aMat[0].mpMat ? 0 : 1);
- SCSIZE nC, nR;
- aMat[i].mpMat->GetDimensions(nC, nR);
- aRes.mpMat = GetNewMat(nC, nR, false);
- if (!aRes.mpMat)
- return aRes;
aRes.mnCol1 = aMat[i].mnCol1;
aRes.mnRow1 = aMat[i].mnRow1;
@@ -1032,8 +1027,9 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO
aRes.mnTab2 = aMat[i].mnTab2;
ScMatrix& rMat = *aMat[i].mpMat;
- ScMatrix& rResMat = *aRes.mpMat;
- rMat.CompareMatrix(rResMat, aComp, i, pOptions);
+ aRes.mpMat = rMat.CompareMatrix(aComp, i, pOptions);
+ if (!aRes.mpMat)
+ return aRes;
}
nCurFmtType = nFuncFmtType = NUMBERFORMAT_LOGICAL;
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 489dcfefb255..3fbdc7f71506 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -200,6 +200,9 @@ class ScMatrixImpl
public:
ScMatrixImpl(SCSIZE nC, SCSIZE nR);
ScMatrixImpl(SCSIZE nC, SCSIZE nR, double fInitVal);
+
+ ScMatrixImpl( size_t nC, size_t nR, const std::vector<bool>& rInitVals );
+
~ScMatrixImpl();
void Clear();
@@ -269,7 +272,7 @@ public:
double GetMaxValue( bool bTextAsZero ) const;
double GetMinValue( bool bTextAsZero ) const;
- void CompareMatrix( ScMatrix& rResMat, sc::Compare& rComp, size_t nMatPos, sc::CompareOptions* pOptions ) const;
+ ScMatrixRef CompareMatrix( sc::Compare& rComp, size_t nMatPos, sc::CompareOptions* pOptions ) const;
void GetDoubleArray( std::vector<double>& rArray, bool bEmptyAsZero ) const;
void MergeDoubleArray( std::vector<double>& rArray, ScMatrix::Op eOp ) const;
@@ -289,6 +292,9 @@ ScMatrixImpl::ScMatrixImpl(SCSIZE nC, SCSIZE nR) :
ScMatrixImpl::ScMatrixImpl(SCSIZE nC, SCSIZE nR, double fInitVal) :
maMat(nR, nC, fInitVal), maMatFlag(nR, nC), pErrorInterpreter(NULL), mbCloneIfConst(true) {}
+ScMatrixImpl::ScMatrixImpl( size_t nC, size_t nR, const std::vector<bool>& rInitVals ) :
+ maMat(nR, nC, rInitVals.begin(), rInitVals.end()), maMatFlag(nR, nC), pErrorInterpreter(NULL), mbCloneIfConst(true) {}
+
ScMatrixImpl::~ScMatrixImpl()
{
Clear();
@@ -1516,8 +1522,8 @@ double ScMatrixImpl::GetMinValue( bool bTextAsZero ) const
return aFunc.getValue();
}
-void ScMatrixImpl::CompareMatrix(
- ScMatrix& rResMat, sc::Compare& rComp, size_t nMatPos, sc::CompareOptions* pOptions ) const
+ScMatrixRef ScMatrixImpl::CompareMatrix(
+ sc::Compare& rComp, size_t nMatPos, sc::CompareOptions* pOptions ) const
{
MatrixImplType::size_pair_type aSize = maMat.size();
size_t nSize = aSize.column * aSize.row;
@@ -1526,8 +1532,10 @@ void ScMatrixImpl::CompareMatrix(
// We assume the result matrix has the same dimension as this matrix.
const std::vector<bool>& rResVal = aFunc.getValues();
- if (nSize == rResVal.size())
- rResMat.pImpl->maMat.set(0, 0, rResVal.begin(), rResVal.end());
+ if (nSize != rResVal.size())
+ ScMatrixRef();
+
+ return ScMatrixRef(new ScMatrix(aSize.column, aSize.row, rResVal));
}
void ScMatrixImpl::GetDoubleArray( std::vector<double>& rArray, bool bEmptyAsZero ) const
@@ -1682,6 +1690,13 @@ ScMatrix::ScMatrix(SCSIZE nC, SCSIZE nR, double fInitVal) :
SAL_WARN_IF( !nR, "sc", "ScMatrix with 0 rows!");
}
+ScMatrix::ScMatrix( size_t nC, size_t nR, const std::vector<bool>& rInitVals ) :
+ pImpl(new ScMatrixImpl(nC, nR, rInitVals)), nRefCnt(0)
+{
+ SAL_WARN_IF( !nC, "sc", "ScMatrix with 0 columns!");
+ SAL_WARN_IF( !nR, "sc", "ScMatrix with 0 rows!");
+}
+
ScMatrix::~ScMatrix()
{
delete pImpl;
@@ -1985,9 +2000,10 @@ double ScMatrix::GetMinValue( bool bTextAsZero ) const
return pImpl->GetMinValue(bTextAsZero);
}
-void ScMatrix::CompareMatrix( ScMatrix& rResMat, sc::Compare& rComp, size_t nMatPos, sc::CompareOptions* pOptions ) const
+ScMatrixRef ScMatrix::CompareMatrix(
+ sc::Compare& rComp, size_t nMatPos, sc::CompareOptions* pOptions ) const
{
- pImpl->CompareMatrix(rResMat, rComp, nMatPos, pOptions);
+ return pImpl->CompareMatrix(rComp, nMatPos, pOptions);
}
void ScMatrix::GetDoubleArray( std::vector<double>& rArray, bool bEmptyAsZero ) const