Kaydet (Commit) 21a1bce4 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Use position objects for more efficient element value lookups.

The underlying multi_type_vector didn't have the concept of position objects
back when the matrix was reworked. It is now available, and there is no reason
why we shouldn't use it to speed things up.

Change-Id: Iac75a5584779c16e6eff7fcd577fc3d717c3c2e7
üst 2c92a92e
...@@ -128,12 +128,13 @@ void compareMatrix(MatrixImplType& rMat) ...@@ -128,12 +128,13 @@ void compareMatrix(MatrixImplType& rMat)
{ {
for (size_t j = 0; j < aDim.column; ++j) for (size_t j = 0; j < aDim.column; ++j)
{ {
mdds::mtm::element_t eType = rMat.get_type(i, j); MatrixImplType::const_position_type aPos = rMat.position(i, j);
mdds::mtm::element_t eType = rMat.get_type(aPos);
if (eType != mdds::mtm::element_numeric && eType != mdds::mtm::element_boolean) if (eType != mdds::mtm::element_numeric && eType != mdds::mtm::element_boolean)
// must be of numeric type (boolean can be numeric). // must be of numeric type (boolean can be numeric).
continue; continue;
double fVal = rMat.get_numeric(i, j); double fVal = rMat.get_numeric(aPos);
if (!::rtl::math::isFinite(fVal)) if (!::rtl::math::isFinite(fVal))
/* FIXME: this silently skips an error instead of propagating it! */ /* FIXME: this silently skips an error instead of propagating it! */
continue; continue;
...@@ -469,20 +470,17 @@ OUString ScMatrixImpl::GetString(SCSIZE nC, SCSIZE nR) const ...@@ -469,20 +470,17 @@ OUString ScMatrixImpl::GetString(SCSIZE nC, SCSIZE nR) const
if (ValidColRowOrReplicated( nC, nR )) if (ValidColRowOrReplicated( nC, nR ))
{ {
double fErr = 0.0; double fErr = 0.0;
switch (maMat.get_type(nR, nC)) MatrixImplType::const_position_type aPos = maMat.position(nR, nC);
switch (maMat.get_type(aPos))
{ {
case mdds::mtm::element_string: case mdds::mtm::element_string:
return maMat.get<OUString>(nR, nC); return maMat.get_string(aPos);
case mdds::mtm::element_empty: case mdds::mtm::element_empty:
return EMPTY_OUSTRING; return EMPTY_OUSTRING;
case mdds::mtm::element_numeric: case mdds::mtm::element_numeric:
OSL_FAIL("ScMatrixImpl::GetString: access error, no string");
fErr = maMat.get<double>(nR, nC);
break;
case mdds::mtm::element_boolean: case mdds::mtm::element_boolean:
OSL_FAIL("ScMatrixImpl::GetString: access error, no string"); OSL_FAIL("ScMatrixImpl::GetString: access error, no string");
fErr = maMat.get<bool>(nR, nC); fErr = maMat.get_numeric(aPos);
break;
default: default:
OSL_FAIL("ScMatrixImpl::GetString: access error, no string"); OSL_FAIL("ScMatrixImpl::GetString: access error, no string");
} }
...@@ -511,10 +509,11 @@ OUString ScMatrixImpl::GetString( SvNumberFormatter& rFormatter, SCSIZE nC, SCSI ...@@ -511,10 +509,11 @@ OUString ScMatrixImpl::GetString( SvNumberFormatter& rFormatter, SCSIZE nC, SCSI
} }
double fVal = 0.0; double fVal = 0.0;
switch (maMat.get_type(nR, nC)) MatrixImplType::const_position_type aPos = maMat.position(nR, nC);
switch (maMat.get_type(aPos))
{ {
case mdds::mtm::element_string: case mdds::mtm::element_string:
return maMat.get<OUString>(nR, nC); return maMat.get_string(aPos);
case mdds::mtm::element_empty: case mdds::mtm::element_empty:
{ {
if (!maMatFlag.get<bool>(nR, nC)) if (!maMatFlag.get<bool>(nR, nC))
...@@ -530,10 +529,8 @@ OUString ScMatrixImpl::GetString( SvNumberFormatter& rFormatter, SCSIZE nC, SCSI ...@@ -530,10 +529,8 @@ OUString ScMatrixImpl::GetString( SvNumberFormatter& rFormatter, SCSIZE nC, SCSI
return aStr; return aStr;
} }
case mdds::mtm::element_numeric: case mdds::mtm::element_numeric:
fVal = maMat.get<double>(nR, nC);
break;
case mdds::mtm::element_boolean: case mdds::mtm::element_boolean:
fVal = maMat.get<bool>(nR, nC); fVal = maMat.get_numeric(aPos);
break; break;
default: default:
; ;
...@@ -558,20 +555,21 @@ ScMatrixValue ScMatrixImpl::Get(SCSIZE nC, SCSIZE nR) const ...@@ -558,20 +555,21 @@ ScMatrixValue ScMatrixImpl::Get(SCSIZE nC, SCSIZE nR) const
ScMatrixValue aVal; ScMatrixValue aVal;
if (ValidColRowOrReplicated(nC, nR)) if (ValidColRowOrReplicated(nC, nR))
{ {
mdds::mtm::element_t eType = maMat.get_type(nR, nC); MatrixImplType::const_position_type aPos = maMat.position(nR, nC);
mdds::mtm::element_t eType = maMat.get_type(aPos);
switch (eType) switch (eType)
{ {
case mdds::mtm::element_boolean: case mdds::mtm::element_boolean:
aVal.nType = SC_MATVAL_BOOLEAN; aVal.nType = SC_MATVAL_BOOLEAN;
aVal.fVal = maMat.get_boolean(nR, nC); aVal.fVal = maMat.get_boolean(aPos);
break; break;
case mdds::mtm::element_numeric: case mdds::mtm::element_numeric:
aVal.nType = SC_MATVAL_VALUE; aVal.nType = SC_MATVAL_VALUE;
aVal.fVal = maMat.get_numeric(nR, nC); aVal.fVal = maMat.get_numeric(aPos);
break; break;
case mdds::mtm::element_string: case mdds::mtm::element_string:
aVal.nType = SC_MATVAL_STRING; aVal.nType = SC_MATVAL_STRING;
aVal.aStr = maMat.get_string(nR, nC); aVal.aStr = maMat.get_string(aPos);
break; break;
case mdds::mtm::element_empty: case mdds::mtm::element_empty:
// Empty path equals empty plus flag. // Empty path equals empty plus flag.
...@@ -775,12 +773,13 @@ double EvalMatrix(const MatrixImplType& rMat) ...@@ -775,12 +773,13 @@ double EvalMatrix(const MatrixImplType& rMat)
{ {
for (size_t j = 0; j < nCols; ++j) for (size_t j = 0; j < nCols; ++j)
{ {
mdds::mtm::element_t eType = rMat.get_type(i, j); MatrixImplType::const_position_type aPos = rMat.position(i, j);
mdds::mtm::element_t eType = rMat.get_type(aPos);
if (eType != mdds::mtm::element_numeric && eType != mdds::mtm::element_boolean) if (eType != mdds::mtm::element_numeric && eType != mdds::mtm::element_boolean)
// assuming a CompareMat this is an error // assuming a CompareMat this is an error
return CreateDoubleError(errIllegalArgument); return CreateDoubleError(errIllegalArgument);
double fVal = rMat.get_numeric(i, j); double fVal = rMat.get_numeric(aPos);
if (!::rtl::math::isFinite(fVal)) if (!::rtl::math::isFinite(fVal))
// DoubleError // DoubleError
return fVal; return fVal;
......
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