sc/inc/compare.hxx | 2 sc/inc/scmatrix.hxx | 8 ++- sc/source/core/inc/interpre.hxx | 2 sc/source/core/tool/interpr1.cxx | 83 +++++++++++++++++---------------------- sc/source/core/tool/scmatrix.cxx | 64 ++++++++++++++++++++++++------ 5 files changed, 99 insertions(+), 60 deletions(-)
New commits: commit 75e6bcba872bc1fd7b4316ff219fb6545e9f542d Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Oct 19 13:55:53 2013 -0400 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 diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index b2a5d8d..f2508a6 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 69cfa10..2cea9a2 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 489dcfe..3fbdc7f 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 commit 8e8b43a03e77dd251876c1de0ac06eeeb09192cd Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Oct 19 13:08:46 2013 -0400 Generate boolean comparison result array in one step. This is faster than doing it in two steps as was previously done. Change-Id: I1417e9c6add9d20ee8d68f0c1c91c7d24a0f79b3 diff --git a/sc/inc/compare.hxx b/sc/inc/compare.hxx index b4e4a50..0bbf8dc 100644 --- a/sc/inc/compare.hxx +++ b/sc/inc/compare.hxx @@ -35,9 +35,11 @@ struct Compare bool bVal[2]; bool bEmpty[2]; + ScQueryOp meOp; bool mbIgnoreCase; Compare( OUString* p1, OUString* p2 ) : + meOp(SC_EQUAL), mbIgnoreCase(true) { pVal[0] = p1; diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index 6fe7a5e..b2a5d8d 100644 --- a/sc/inc/scmatrix.hxx +++ b/sc/inc/scmatrix.hxx @@ -109,6 +109,8 @@ struct ScMatrixValue */ class SC_DLLPUBLIC ScMatrix { + friend class ScMatrixImpl; + ScMatrixImpl* pImpl; mutable size_t nRefCnt; // reference count diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index d308936..69cfa10 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -883,6 +883,7 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO { OUString aVal1, aVal2; sc::Compare aComp( &aVal1, &aVal2 ); + aComp.meOp = eOp; aComp.mbIgnoreCase = pDok->GetDocOptions().IsIgnoreCase(); sc::RangeMatrix aMat[2]; ScAddress aAdr; @@ -1033,32 +1034,6 @@ sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pO ScMatrix& rMat = *aMat[i].mpMat; ScMatrix& rResMat = *aRes.mpMat; rMat.CompareMatrix(rResMat, aComp, i, pOptions); - - switch (eOp) - { - case SC_EQUAL: - aRes.mpMat->CompareEqual(); - break; - case SC_LESS: - aRes.mpMat->CompareLess(); - break; - case SC_GREATER: - aRes.mpMat->CompareGreater(); - break; - case SC_LESS_EQUAL: - aRes.mpMat->CompareLessEqual(); - break; - case SC_GREATER_EQUAL: - aRes.mpMat->CompareGreaterEqual(); - break; - case SC_NOT_EQUAL: - aRes.mpMat->CompareNotEqual(); - break; - default: - OSL_TRACE( "ScInterpreter::QueryMat: unhandled comparison operator: %d", (int)eOp); - aRes.mpMat.reset(); - return aRes; - } } nCurFmtType = nFuncFmtType = NUMBERFORMAT_LOGICAL; diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx index cc2106d..489dcfe 100644 --- a/sc/source/core/tool/scmatrix.cxx +++ b/sc/source/core/tool/scmatrix.cxx @@ -1217,12 +1217,36 @@ class CompareMatrixFunc : std::unary_function<MatrixImplType::element_block_type sc::Compare& mrComp; size_t mnMatPos; sc::CompareOptions* mpOptions; - - std::vector<double> maResValues; + std::vector<bool> maResValues; void compare() { - maResValues.push_back(sc::CompareFunc(mrComp, mpOptions)); + double fVal = sc::CompareFunc(mrComp, mpOptions); + bool bRes = false; + switch (mrComp.meOp) + { + case SC_EQUAL: + bRes = fVal == 0.0; + break; + case SC_LESS: + bRes = fVal < 0.0; + break; + case SC_GREATER: + bRes = fVal > 0.0; + break; + case SC_LESS_EQUAL: + bRes = fVal <= 0.0; + break; + case SC_GREATER_EQUAL: + bRes = fVal >= 0.0; + break; + case SC_NOT_EQUAL: + bRes = fVal != 0.0; + break; + default: + OSL_TRACE( "CompareMatrixFunc: unhandled comparison operator: %d", (int)mrComp.meOp); + } + maResValues.push_back(bRes); } public: @@ -1295,7 +1319,7 @@ public: } } - const std::vector<double>& getValues() const + const std::vector<bool>& getValues() const { return maResValues; } @@ -1501,9 +1525,9 @@ void ScMatrixImpl::CompareMatrix( maMat.walk(aFunc); // We assume the result matrix has the same dimension as this matrix. - const std::vector<double>& rResVal = aFunc.getValues(); + const std::vector<bool>& rResVal = aFunc.getValues(); if (nSize == rResVal.size()) - rResMat.PutDouble(&rResVal[0], rResVal.size(), 0, 0); + rResMat.pImpl->maMat.set(0, 0, rResVal.begin(), rResVal.end()); } void ScMatrixImpl::GetDoubleArray( std::vector<double>& rArray, bool bEmptyAsZero ) const commit 72d4b574f11979d5487309737172869e9c3181a9 Author: Kohei Yoshida <kohei.yosh...@collabora.com> Date: Sat Oct 19 11:27:24 2013 -0400 Do the two matrix comparisons both in CompareMat(). Change-Id: I1b4dab3f57dd7df556aa13fdd44a2d3ba2b01bd7 diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index 11adc34..99fa566 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -386,7 +386,7 @@ double Compare(); /** @param pOptions NULL means case sensitivity document option is to be used! */ -sc::RangeMatrix CompareMat( sc::CompareOptions* pOptions = NULL ); +sc::RangeMatrix CompareMat( ScQueryOp eOp, sc::CompareOptions* pOptions = NULL ); ScMatrixRef QueryMat( const ScMatrixRef& pMat, sc::CompareOptions& rOptions ); void ScEqual(); void ScNotEqual(); diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index e764d21..d308936 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -879,7 +879,7 @@ double ScInterpreter::Compare() } -sc::RangeMatrix ScInterpreter::CompareMat( sc::CompareOptions* pOptions ) +sc::RangeMatrix ScInterpreter::CompareMat( ScQueryOp eOp, sc::CompareOptions* pOptions ) { OUString aVal1, aVal2; sc::Compare aComp( &aVal1, &aVal2 ); @@ -987,6 +987,32 @@ sc::RangeMatrix ScInterpreter::CompareMat( sc::CompareOptions* pOptions ) aRes.mpMat->PutString(mrStrPool.intern(ScGlobal::GetRscString(STR_NO_VALUE)), j, k); } } + + switch (eOp) + { + case SC_EQUAL: + aRes.mpMat->CompareEqual(); + break; + case SC_LESS: + aRes.mpMat->CompareLess(); + break; + case SC_GREATER: + aRes.mpMat->CompareGreater(); + break; + case SC_LESS_EQUAL: + aRes.mpMat->CompareLessEqual(); + break; + case SC_GREATER_EQUAL: + aRes.mpMat->CompareGreaterEqual(); + break; + case SC_NOT_EQUAL: + aRes.mpMat->CompareNotEqual(); + break; + default: + OSL_TRACE( "ScInterpreter::QueryMat: unhandled comparison operator: %d", (int)eOp); + aRes.mpMat.reset(); + return aRes; + } } else if (aMat[0].mpMat || aMat[1].mpMat) { @@ -1007,6 +1033,32 @@ sc::RangeMatrix ScInterpreter::CompareMat( sc::CompareOptions* pOptions ) ScMatrix& rMat = *aMat[i].mpMat; ScMatrix& rResMat = *aRes.mpMat; rMat.CompareMatrix(rResMat, aComp, i, pOptions); + + switch (eOp) + { + case SC_EQUAL: + aRes.mpMat->CompareEqual(); + break; + case SC_LESS: + aRes.mpMat->CompareLess(); + break; + case SC_GREATER: + aRes.mpMat->CompareGreater(); + break; + case SC_LESS_EQUAL: + aRes.mpMat->CompareLessEqual(); + break; + case SC_GREATER_EQUAL: + aRes.mpMat->CompareGreaterEqual(); + break; + case SC_NOT_EQUAL: + aRes.mpMat->CompareNotEqual(); + break; + default: + OSL_TRACE( "ScInterpreter::QueryMat: unhandled comparison operator: %d", (int)eOp); + aRes.mpMat.reset(); + return aRes; + } } nCurFmtType = nFuncFmtType = NUMBERFORMAT_LOGICAL; @@ -1024,7 +1076,7 @@ ScMatrixRef ScInterpreter::QueryMat( const ScMatrixRef& pMat, sc::CompareOptions PushString(rItem.maString.getString()); else PushDouble(rItem.mfVal); - ScMatrixRef pResultMatrix = CompareMat( &rOptions).mpMat; + ScMatrixRef pResultMatrix = CompareMat(rOptions.aQueryEntry.eOp, &rOptions).mpMat; nCurFmtType = nSaveCurFmtType; nFuncFmtType = nSaveFuncFmtType; if (nGlobalError || !pResultMatrix) @@ -1033,30 +1085,6 @@ ScMatrixRef ScInterpreter::QueryMat( const ScMatrixRef& pMat, sc::CompareOptions return pResultMatrix; } - switch (rOptions.aQueryEntry.eOp) - { - case SC_EQUAL: - pResultMatrix->CompareEqual(); - break; - case SC_LESS: - pResultMatrix->CompareLess(); - break; - case SC_GREATER: - pResultMatrix->CompareGreater(); - break; - case SC_LESS_EQUAL: - pResultMatrix->CompareLessEqual(); - break; - case SC_GREATER_EQUAL: - pResultMatrix->CompareGreaterEqual(); - break; - case SC_NOT_EQUAL: - pResultMatrix->CompareNotEqual(); - break; - default: - SetError( errIllegalArgument); - OSL_TRACE( "ScInterpreter::QueryMat: unhandled comparison operator: %d", (int)rOptions.aQueryEntry.eOp); - } return pResultMatrix; } @@ -1064,14 +1092,13 @@ void ScInterpreter::ScEqual() { if ( GetStackType(1) == svMatrix || GetStackType(2) == svMatrix ) { - sc::RangeMatrix aMat = CompareMat(); + sc::RangeMatrix aMat = CompareMat(SC_EQUAL); if (!aMat.mpMat) { PushIllegalParameter(); return; } - aMat.mpMat->CompareEqual(); PushMatrix(aMat); } else @@ -1083,14 +1110,13 @@ void ScInterpreter::ScNotEqual() { if ( GetStackType(1) == svMatrix || GetStackType(2) == svMatrix ) { - sc::RangeMatrix aMat = CompareMat(); + sc::RangeMatrix aMat = CompareMat(SC_NOT_EQUAL); if (!aMat.mpMat) { PushIllegalParameter(); return; } - aMat.mpMat->CompareNotEqual(); PushMatrix(aMat); } else @@ -1102,14 +1128,13 @@ void ScInterpreter::ScLess() { if ( GetStackType(1) == svMatrix || GetStackType(2) == svMatrix ) { - sc::RangeMatrix aMat = CompareMat(); + sc::RangeMatrix aMat = CompareMat(SC_LESS); if (!aMat.mpMat) { PushIllegalParameter(); return; } - aMat.mpMat->CompareLess(); PushMatrix(aMat); } else @@ -1121,14 +1146,13 @@ void ScInterpreter::ScGreater() { if ( GetStackType(1) == svMatrix || GetStackType(2) == svMatrix ) { - sc::RangeMatrix aMat = CompareMat(); + sc::RangeMatrix aMat = CompareMat(SC_GREATER); if (!aMat.mpMat) { PushIllegalParameter(); return; } - aMat.mpMat->CompareGreater(); PushMatrix(aMat); } else @@ -1140,14 +1164,13 @@ void ScInterpreter::ScLessEqual() { if ( GetStackType(1) == svMatrix || GetStackType(2) == svMatrix ) { - sc::RangeMatrix aMat = CompareMat(); + sc::RangeMatrix aMat = CompareMat(SC_LESS_EQUAL); if (!aMat.mpMat) { PushIllegalParameter(); return; } - aMat.mpMat->CompareLessEqual(); PushMatrix(aMat); } else @@ -1159,14 +1182,13 @@ void ScInterpreter::ScGreaterEqual() { if ( GetStackType(1) == svMatrix || GetStackType(2) == svMatrix ) { - sc::RangeMatrix aMat = CompareMat(); + sc::RangeMatrix aMat = CompareMat(SC_GREATER_EQUAL); if (!aMat.mpMat) { PushIllegalParameter(); return; } - aMat.mpMat->CompareGreaterEqual(); PushMatrix(aMat); } else _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits