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 ...@@ -82,6 +82,8 @@ class ScFormulaResult
bool mbEmpty :1; // empty cell result bool mbEmpty :1; // empty cell result
bool mbEmptyDisplayedAsString :1; // only if mbEmpty bool mbEmptyDisplayedAsString :1; // only if mbEmpty
Multiline meMultiline :2; // result is multiline 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 /** Reset mnError, mbEmpty and mbEmptyDisplayedAsString to their defaults
prior to assigning other types */ prior to assigning other types */
......
...@@ -25,13 +25,15 @@ FormulaResultValue::FormulaResultValue( FormulaError nErr ) : meType(Error), mfV ...@@ -25,13 +25,15 @@ FormulaResultValue::FormulaResultValue( FormulaError nErr ) : meType(Error), mfV
ScFormulaResult::ScFormulaResult() : ScFormulaResult::ScFormulaResult() :
mpToken(nullptr), mnError(FormulaError::NONE), mbToken(true), mpToken(nullptr), mnError(FormulaError::NONE), mbToken(true),
mbEmpty(false), mbEmptyDisplayedAsString(false), mbEmpty(false), mbEmptyDisplayedAsString(false),
meMultiline(MULTILINE_UNKNOWN) {} meMultiline(MULTILINE_UNKNOWN),
mbValueCached(false) {}
ScFormulaResult::ScFormulaResult( const ScFormulaResult & r ) : ScFormulaResult::ScFormulaResult( const ScFormulaResult & r ) :
mnError( r.mnError), mbToken( r.mbToken), mnError( r.mnError), mbToken( r.mbToken),
mbEmpty( r.mbEmpty), mbEmpty( r.mbEmpty),
mbEmptyDisplayedAsString( r.mbEmptyDisplayedAsString), mbEmptyDisplayedAsString( r.mbEmptyDisplayedAsString),
meMultiline( r.meMultiline) meMultiline( r.meMultiline),
mbValueCached( r.mbValueCached)
{ {
if (mbToken) if (mbToken)
{ {
...@@ -59,7 +61,7 @@ ScFormulaResult::ScFormulaResult( const ScFormulaResult & r ) : ...@@ -59,7 +61,7 @@ ScFormulaResult::ScFormulaResult( const ScFormulaResult & r ) :
ScFormulaResult::ScFormulaResult( const formula::FormulaToken* p ) : ScFormulaResult::ScFormulaResult( const formula::FormulaToken* p ) :
mnError(FormulaError::NONE), mbToken(false), mbEmpty(false), mbEmptyDisplayedAsString(false), mnError(FormulaError::NONE), mbToken(false), mbEmpty(false), mbEmptyDisplayedAsString(false),
meMultiline(MULTILINE_UNKNOWN) meMultiline(MULTILINE_UNKNOWN), mbValueCached(false)
{ {
SetToken( p); SetToken( p);
} }
...@@ -76,6 +78,7 @@ void ScFormulaResult::ResetToDefaults() ...@@ -76,6 +78,7 @@ void ScFormulaResult::ResetToDefaults()
mbEmpty = false; mbEmpty = false;
mbEmptyDisplayedAsString = false; mbEmptyDisplayedAsString = false;
meMultiline = MULTILINE_UNKNOWN; meMultiline = MULTILINE_UNKNOWN;
mbValueCached = false;
} }
void ScFormulaResult::ResolveToken( const formula::FormulaToken * p ) void ScFormulaResult::ResolveToken( const formula::FormulaToken * p )
...@@ -110,6 +113,7 @@ void ScFormulaResult::ResolveToken( const formula::FormulaToken * p ) ...@@ -110,6 +113,7 @@ void ScFormulaResult::ResolveToken( const formula::FormulaToken * p )
p->DecRef(); p->DecRef();
mbToken = false; mbToken = false;
meMultiline = MULTILINE_FALSE; meMultiline = MULTILINE_FALSE;
mbValueCached = true;
break; break;
default: default:
mpToken = p; mpToken = p;
...@@ -151,7 +155,7 @@ void ScFormulaResult::Assign( const ScFormulaResult & r ) ...@@ -151,7 +155,7 @@ void ScFormulaResult::Assign( const ScFormulaResult & r )
SetDouble( r.mfValue); SetDouble( r.mfValue);
// If there was an error there will be an error, no matter what Set...() // If there was an error there will be an error, no matter what Set...()
// methods did. // methods did.
mnError = r.mnError; SetResultError(r.mnError);
} }
void ScFormulaResult::SetToken( const formula::FormulaToken* p ) void ScFormulaResult::SetToken( const formula::FormulaToken* p )
...@@ -216,6 +220,7 @@ void ScFormulaResult::SetDouble( double f ) ...@@ -216,6 +220,7 @@ void ScFormulaResult::SetDouble( double f )
mfValue = f; mfValue = f;
mbToken = false; mbToken = false;
meMultiline = MULTILINE_FALSE; meMultiline = MULTILINE_FALSE;
mbValueCached = true;
} }
} }
...@@ -335,6 +340,12 @@ bool ScFormulaResult::IsMultiline() const ...@@ -335,6 +340,12 @@ bool ScFormulaResult::IsMultiline() const
bool ScFormulaResult::GetErrorOrDouble( FormulaError& rErr, double& rVal ) const bool ScFormulaResult::GetErrorOrDouble( FormulaError& rErr, double& rVal ) const
{ {
if (mbValueCached)
{
rVal = mfValue;
return true;
}
if (mnError != FormulaError::NONE) if (mnError != FormulaError::NONE)
{ {
rErr = mnError; rErr = mnError;
...@@ -368,6 +379,9 @@ bool ScFormulaResult::GetErrorOrDouble( FormulaError& rErr, double& rVal ) const ...@@ -368,6 +379,9 @@ bool ScFormulaResult::GetErrorOrDouble( FormulaError& rErr, double& rVal ) const
sc::FormulaResultValue ScFormulaResult::GetResult() const sc::FormulaResultValue ScFormulaResult::GetResult() const
{ {
if (mbValueCached)
return sc::FormulaResultValue(mfValue);
if (mnError != FormulaError::NONE) if (mnError != FormulaError::NONE)
return sc::FormulaResultValue(mnError); return sc::FormulaResultValue(mnError);
...@@ -424,6 +438,8 @@ FormulaError ScFormulaResult::GetResultError() const ...@@ -424,6 +438,8 @@ FormulaError ScFormulaResult::GetResultError() const
void ScFormulaResult::SetResultError( FormulaError nErr ) void ScFormulaResult::SetResultError( FormulaError nErr )
{ {
mnError = nErr; mnError = nErr;
if (mnError != FormulaError::NONE)
mbValueCached = false;
} }
formula::FormulaConstTokenRef ScFormulaResult::GetToken() const formula::FormulaConstTokenRef ScFormulaResult::GetToken() const
...@@ -443,6 +459,9 @@ formula::FormulaConstTokenRef ScFormulaResult::GetCellResultToken() const ...@@ -443,6 +459,9 @@ formula::FormulaConstTokenRef ScFormulaResult::GetCellResultToken() const
double ScFormulaResult::GetDouble() const double ScFormulaResult::GetDouble() const
{ {
if (mbValueCached)
return mfValue;
if (mbToken) if (mbToken)
{ {
// Should really not be of type formula::svDouble here. // Should really not be of type formula::svDouble here.
...@@ -536,6 +555,7 @@ void ScFormulaResult::SetHybridDouble( double f ) ...@@ -536,6 +555,7 @@ void ScFormulaResult::SetHybridDouble( double f )
mfValue = f; mfValue = f;
mbToken = false; mbToken = false;
meMultiline = MULTILINE_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