Kaydet (Commit) 2d41f3ac authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Reduce branching on empty matrix elements as well.

This makes a big difference in performance.

Change-Id: I88b48d10ff575d80c1c139278dc207d921f15848
üst 426708e7
...@@ -70,6 +70,11 @@ double CompareFunc( double fCell1, const Compare::Cell& rCell2, CompareOptions* ...@@ -70,6 +70,11 @@ double CompareFunc( double fCell1, const Compare::Cell& rCell2, CompareOptions*
double CompareFunc( const Compare::Cell& rCell1, double fCell2, CompareOptions* pOptions = NULL ); double CompareFunc( const Compare::Cell& rCell1, double fCell2, CompareOptions* pOptions = NULL );
double CompareFunc( double fCell1, double fCell2 ); double CompareFunc( double fCell1, double fCell2 );
/**
* Left cell is empty while the right cell is numeric.
*/
double CompareEmptyToNumericFunc( double fCell2 );
} }
#endif #endif
......
...@@ -357,6 +357,26 @@ double CompareFunc( double fCell1, double fCell2 ) ...@@ -357,6 +357,26 @@ double CompareFunc( double fCell1, double fCell2 )
return fRes; return fRes;
} }
double CompareEmptyToNumericFunc( double fCell2 )
{
// Keep DoubleError if encountered
// #i40539# if bEmpty is set, bVal/nVal are uninitialized
if (!rtl::math::isFinite(fCell2))
return fCell2;
double fRes = 0;
if (fCell2 != 0.0)
{
if (fCell2 < 0.0)
fRes = 1; // empty cell > -x
else
fRes = -1; // empty cell < x
}
// else: empty cell == 0.0
return fRes;
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -1359,6 +1359,13 @@ class CompareMatrixToNumericFunc : std::unary_function<MatrixImplType::element_b ...@@ -1359,6 +1359,13 @@ class CompareMatrixToNumericFunc : std::unary_function<MatrixImplType::element_b
maResValues.push_back(evaluate(fVal, mrComp.meOp)); maResValues.push_back(evaluate(fVal, mrComp.meOp));
} }
void compareLeftEmpty( size_t nSize )
{
double fVal = sc::CompareEmptyToNumericFunc(mfRightValue);
bool bRes = evaluate(fVal, mrComp.meOp);
maResValues.resize(maResValues.size() + nSize, bRes);
}
public: public:
CompareMatrixToNumericFunc( size_t nResSize, sc::Compare& rComp, double fRightValue, sc::CompareOptions* pOptions ) : CompareMatrixToNumericFunc( size_t nResSize, sc::Compare& rComp, double fRightValue, sc::CompareOptions* pOptions ) :
mrComp(rComp), mfRightValue(fRightValue), mpOptions(pOptions) mrComp(rComp), mfRightValue(fRightValue), mpOptions(pOptions)
...@@ -1409,13 +1416,8 @@ public: ...@@ -1409,13 +1416,8 @@ public:
} }
break; break;
case mdds::mtm::element_empty: case mdds::mtm::element_empty:
{ compareLeftEmpty(node.size);
rCell.mbValue = false; break;
rCell.mbEmpty = true;
rCell.maStr = svl::SharedString::getEmptyString();
for (size_t i = 0; i < node.size; ++i)
compare();
}
default: default:
; ;
} }
...@@ -1627,7 +1629,9 @@ ScMatrixRef ScMatrixImpl::CompareMatrix( ...@@ -1627,7 +1629,9 @@ ScMatrixRef ScMatrixImpl::CompareMatrix(
{ {
if (rComp.maCells[1].mbValue && !rComp.maCells[1].mbEmpty) if (rComp.maCells[1].mbValue && !rComp.maCells[1].mbEmpty)
{ {
// Matrix on the left, and a numeric value on the right. // Matrix on the left, and a numeric value on the right. Use a
// function object that has much less branching for much better
// performance.
CompareMatrixToNumericFunc aFunc(nSize, rComp, rComp.maCells[1].mfValue, pOptions); CompareMatrixToNumericFunc aFunc(nSize, rComp, rComp.maCells[1].mfValue, pOptions);
maMat.walk(aFunc); maMat.walk(aFunc);
......
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