Kaydet (Commit) 77f7b476 authored tarafından Dennis Francis's avatar Dennis Francis Kaydeden (comit) Luboš Luňák

Allow fast result return for formula-cells with...

"double" result which is a very frequent use-case.
This improves overall running times in most cases,
not just for the threaded path.

Change-Id: I18d10ee3cea613923e2057e746a6a8187bb18647
Reviewed-on: https://gerrit.libreoffice.org/59395
Tested-by: Jenkins
Reviewed-by: 's avatarLuboš Luňák <l.lunak@collabora.com>
üst dc510c2e
......@@ -82,6 +82,8 @@ class ScFormulaResult
bool mbEmpty :1; // empty cell result
bool mbEmptyDisplayedAsString :1; // only if mbEmpty
Multiline meMultiline :2; // result is multiline
// If set it implies that the result is a simple double (in mfValue) and no error
bool mbValueCached :1;
/** Reset mnError, mbEmpty and mbEmptyDisplayedAsString to their defaults
prior to assigning other types */
......
......@@ -25,13 +25,15 @@ FormulaResultValue::FormulaResultValue( FormulaError nErr ) : meType(Error), mfV
ScFormulaResult::ScFormulaResult() :
mpToken(nullptr), mnError(FormulaError::NONE), mbToken(true),
mbEmpty(false), mbEmptyDisplayedAsString(false),
meMultiline(MULTILINE_UNKNOWN) {}
meMultiline(MULTILINE_UNKNOWN),
mbValueCached(false) {}
ScFormulaResult::ScFormulaResult( const ScFormulaResult & r ) :
mnError( r.mnError), mbToken( r.mbToken),
mbEmpty( r.mbEmpty),
mbEmptyDisplayedAsString( r.mbEmptyDisplayedAsString),
meMultiline( r.meMultiline)
meMultiline( r.meMultiline),
mbValueCached( r.mbValueCached)
{
if (mbToken)
{
......@@ -59,7 +61,7 @@ ScFormulaResult::ScFormulaResult( const ScFormulaResult & r ) :
ScFormulaResult::ScFormulaResult( const formula::FormulaToken* p ) :
mnError(FormulaError::NONE), mbToken(false), mbEmpty(false), mbEmptyDisplayedAsString(false),
meMultiline(MULTILINE_UNKNOWN)
meMultiline(MULTILINE_UNKNOWN), mbValueCached(false)
{
SetToken( p);
}
......@@ -76,6 +78,7 @@ void ScFormulaResult::ResetToDefaults()
mbEmpty = false;
mbEmptyDisplayedAsString = false;
meMultiline = MULTILINE_UNKNOWN;
mbValueCached = false;
}
void ScFormulaResult::ResolveToken( const formula::FormulaToken * p )
......@@ -110,6 +113,7 @@ void ScFormulaResult::ResolveToken( const formula::FormulaToken * p )
p->DecRef();
mbToken = false;
meMultiline = MULTILINE_FALSE;
mbValueCached = true;
break;
default:
mpToken = p;
......@@ -151,7 +155,7 @@ void ScFormulaResult::Assign( const ScFormulaResult & r )
SetDouble( r.mfValue);
// If there was an error there will be an error, no matter what Set...()
// methods did.
mnError = r.mnError;
SetResultError(r.mnError);
}
void ScFormulaResult::SetToken( const formula::FormulaToken* p )
......@@ -216,6 +220,7 @@ void ScFormulaResult::SetDouble( double f )
mfValue = f;
mbToken = false;
meMultiline = MULTILINE_FALSE;
mbValueCached = true;
}
}
......@@ -335,6 +340,12 @@ bool ScFormulaResult::IsMultiline() const
bool ScFormulaResult::GetErrorOrDouble( FormulaError& rErr, double& rVal ) const
{
if (mbValueCached)
{
rVal = mfValue;
return true;
}
if (mnError != FormulaError::NONE)
{
rErr = mnError;
......@@ -368,6 +379,9 @@ bool ScFormulaResult::GetErrorOrDouble( FormulaError& rErr, double& rVal ) const
sc::FormulaResultValue ScFormulaResult::GetResult() const
{
if (mbValueCached)
return sc::FormulaResultValue(mfValue);
if (mnError != FormulaError::NONE)
return sc::FormulaResultValue(mnError);
......@@ -424,6 +438,8 @@ FormulaError ScFormulaResult::GetResultError() const
void ScFormulaResult::SetResultError( FormulaError nErr )
{
mnError = nErr;
if (mnError != FormulaError::NONE)
mbValueCached = false;
}
formula::FormulaConstTokenRef ScFormulaResult::GetToken() const
......@@ -443,6 +459,9 @@ formula::FormulaConstTokenRef ScFormulaResult::GetCellResultToken() const
double ScFormulaResult::GetDouble() const
{
if (mbValueCached)
return mfValue;
if (mbToken)
{
// Should really not be of type formula::svDouble here.
......@@ -536,6 +555,7 @@ void ScFormulaResult::SetHybridDouble( double f )
mfValue = f;
mbToken = false;
meMultiline = MULTILINE_FALSE;
mbValueCached = true;
}
}
......
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