Kaydet (Commit) bbe088bc authored tarafından Markus Mohrhard's avatar Markus Mohrhard

cache calls to mdds:mixed_type_matrix::size, related fdo#47299

üst 7be7f9a7
...@@ -170,6 +170,7 @@ class ScMatrixImpl ...@@ -170,6 +170,7 @@ class ScMatrixImpl
ScMatrix::DensityType meType; ScMatrix::DensityType meType;
ScInterpreter* pErrorInterpreter; ScInterpreter* pErrorInterpreter;
bool mbCloneIfConst; // Whether the matrix is cloned with a CloneIfConst() call. bool mbCloneIfConst; // Whether the matrix is cloned with a CloneIfConst() call.
MatrixImplType::size_pair_type maCachedSize;
ScMatrixImpl(); ScMatrixImpl();
ScMatrixImpl(const ScMatrixImpl&); ScMatrixImpl(const ScMatrixImpl&);
...@@ -243,6 +244,7 @@ ScMatrixImpl::ScMatrixImpl(SCSIZE nC, SCSIZE nR, ScMatrix::DensityType eType) : ...@@ -243,6 +244,7 @@ ScMatrixImpl::ScMatrixImpl(SCSIZE nC, SCSIZE nR, ScMatrix::DensityType eType) :
pErrorInterpreter(NULL), pErrorInterpreter(NULL),
mbCloneIfConst(true) mbCloneIfConst(true)
{ {
maCachedSize = maMat.size();
} }
ScMatrixImpl::~ScMatrixImpl() ScMatrixImpl::~ScMatrixImpl()
...@@ -253,6 +255,7 @@ ScMatrixImpl::~ScMatrixImpl() ...@@ -253,6 +255,7 @@ ScMatrixImpl::~ScMatrixImpl()
void ScMatrixImpl::Clear() void ScMatrixImpl::Clear()
{ {
maMat.clear(); maMat.clear();
maCachedSize = maMat.size();
} }
void ScMatrixImpl::SetImmutable(bool bVal) void ScMatrixImpl::SetImmutable(bool bVal)
...@@ -268,6 +271,7 @@ bool ScMatrixImpl::IsImmutable() const ...@@ -268,6 +271,7 @@ bool ScMatrixImpl::IsImmutable() const
void ScMatrixImpl::Resize(SCSIZE nC, SCSIZE nR) void ScMatrixImpl::Resize(SCSIZE nC, SCSIZE nR)
{ {
maMat.resize(nR, nC); maMat.resize(nR, nC);
maCachedSize = maMat.size();
} }
ScMatrix::DensityType ScMatrixImpl::GetDensityType() const ScMatrix::DensityType ScMatrixImpl::GetDensityType() const
...@@ -282,40 +286,35 @@ void ScMatrixImpl::SetErrorInterpreter( ScInterpreter* p) ...@@ -282,40 +286,35 @@ void ScMatrixImpl::SetErrorInterpreter( ScInterpreter* p)
void ScMatrixImpl::GetDimensions( SCSIZE& rC, SCSIZE& rR) const void ScMatrixImpl::GetDimensions( SCSIZE& rC, SCSIZE& rR) const
{ {
MatrixImplType::size_pair_type aDims = maMat.size(); rR = maCachedSize.first;
rR = aDims.first; rC = maCachedSize.second;
rC = aDims.second;
} }
SCSIZE ScMatrixImpl::GetElementCount() const SCSIZE ScMatrixImpl::GetElementCount() const
{ {
MatrixImplType::size_pair_type aDims = maMat.size(); return maCachedSize.first * maCachedSize.second;
return aDims.first * aDims.second;
} }
bool ScMatrixImpl::ValidColRow( SCSIZE nC, SCSIZE nR) const bool ScMatrixImpl::ValidColRow( SCSIZE nC, SCSIZE nR) const
{ {
MatrixImplType::size_pair_type aDims = maMat.size(); return nR < maCachedSize.first && nC < maCachedSize.second;
return nR < aDims.first && nC < aDims.second;
} }
bool ScMatrixImpl::ValidColRowReplicated( SCSIZE & rC, SCSIZE & rR ) const bool ScMatrixImpl::ValidColRowReplicated( SCSIZE & rC, SCSIZE & rR ) const
{ {
pair<size_t, size_t> aDims = maMat.size(); if (maCachedSize.second == 1 && maCachedSize.first == 1)
if (aDims.second == 1 && aDims.first == 1)
{ {
rC = 0; rC = 0;
rR = 0; rR = 0;
return true; return true;
} }
else if (aDims.second == 1 && rR < aDims.first) else if (maCachedSize.second == 1 && rR < maCachedSize.first)
{ {
// single column matrix. // single column matrix.
rC = 0; rC = 0;
return true; return true;
} }
else if (aDims.first == 1 && rC < aDims.second) else if (maCachedSize.first == 1 && rC < maCachedSize.second)
{ {
// single row matrix. // single row matrix.
rR = 0; rR = 0;
...@@ -639,8 +638,7 @@ bool ScMatrixImpl::IsNumeric() const ...@@ -639,8 +638,7 @@ bool ScMatrixImpl::IsNumeric() const
void ScMatrixImpl::MatCopy(ScMatrixImpl& mRes) const void ScMatrixImpl::MatCopy(ScMatrixImpl& mRes) const
{ {
MatrixImplType::size_pair_type s1 = maMat.size(), s2 = mRes.maMat.size(); if (maCachedSize.first > mRes.maCachedSize.first || maCachedSize.second > mRes.maCachedSize.second)
if (s1.first > s2.first || s1.second > s2.second)
{ {
// destination matrix is not large enough. // destination matrix is not large enough.
OSL_FAIL("ScMatrixImpl::MatCopy: dimension error"); OSL_FAIL("ScMatrixImpl::MatCopy: dimension error");
...@@ -648,12 +646,14 @@ void ScMatrixImpl::MatCopy(ScMatrixImpl& mRes) const ...@@ -648,12 +646,14 @@ void ScMatrixImpl::MatCopy(ScMatrixImpl& mRes) const
} }
mRes.maMat.assign(maMat); mRes.maMat.assign(maMat);
mRes.maCachedSize = mRes.maMat.size();
} }
void ScMatrixImpl::MatTrans(ScMatrixImpl& mRes) const void ScMatrixImpl::MatTrans(ScMatrixImpl& mRes) const
{ {
mRes.maMat = maMat; mRes.maMat = maMat;
mRes.maMat.transpose(); mRes.maMat.transpose();
mRes.maCachedSize = mRes.maMat.size();
} }
void ScMatrixImpl::FillDouble( double fVal, SCSIZE nC1, SCSIZE nR1, SCSIZE nC2, SCSIZE nR2 ) void ScMatrixImpl::FillDouble( double fVal, SCSIZE nC1, SCSIZE nR1, SCSIZE nC2, SCSIZE nR2 )
...@@ -720,8 +720,7 @@ template <typename _Evaluator> ...@@ -720,8 +720,7 @@ template <typename _Evaluator>
bool EvalMatrix(const MatrixImplType& rMat) bool EvalMatrix(const MatrixImplType& rMat)
{ {
_Evaluator aEval; _Evaluator aEval;
pair<size_t,size_t> aDim = rMat.size(); size_t nRows = rMat.size().first, nCols = rMat.size().second;
size_t nRows = aDim.first, nCols = aDim.second;
for (size_t i = 0; i < nRows; ++i) for (size_t i = 0; i < nRows; ++i)
{ {
for (size_t j = 0; j < nCols; ++j) for (size_t j = 0; j < nCols; ++j)
...@@ -911,7 +910,7 @@ size_t ScMatrixImpl::Count(bool bCountStrings) const ...@@ -911,7 +910,7 @@ size_t ScMatrixImpl::Count(bool bCountStrings) const
void ScMatrixImpl::CalcPosition(SCSIZE nIndex, SCSIZE& rC, SCSIZE& rR) const void ScMatrixImpl::CalcPosition(SCSIZE nIndex, SCSIZE& rC, SCSIZE& rR) const
{ {
SCSIZE nRowSize = maMat.size().first; SCSIZE nRowSize = maCachedSize.first;
rC = nIndex / nRowSize; rC = nIndex / nRowSize;
rR = nIndex - rC*nRowSize; rR = nIndex - rC*nRowSize;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment