diff options
author | Dennis Francis <dennis.francis@collabora.co.uk> | 2018-07-11 17:19:28 +0530 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2018-08-23 11:29:53 +0200 |
commit | 3d92276f4591ec6f949abcd440ef1544f9282c0b (patch) | |
tree | 22c345aa47ae892b531d5170a0fed88c5b318f54 /sc | |
parent | 69f6d82c51b1c33c5a5eceafb254b000dc410530 (diff) |
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: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/formularesult.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/formularesult.cxx | 28 |
2 files changed, 26 insertions, 4 deletions
diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx index 4797b5939522..a7b5ea8f3da8 100644 --- a/sc/inc/formularesult.hxx +++ b/sc/inc/formularesult.hxx @@ -76,6 +76,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 */ diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx index 1b3fcd995f8a..7c0f1a1a570d 100644 --- a/sc/source/core/tool/formularesult.cxx +++ b/sc/source/core/tool/formularesult.cxx @@ -22,13 +22,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) { @@ -56,7 +58,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); } @@ -73,6 +75,7 @@ void ScFormulaResult::ResetToDefaults() mbEmpty = false; mbEmptyDisplayedAsString = false; meMultiline = MULTILINE_UNKNOWN; + mbValueCached = false; } void ScFormulaResult::ResolveToken( const formula::FormulaToken * p ) @@ -107,6 +110,7 @@ void ScFormulaResult::ResolveToken( const formula::FormulaToken * p ) p->DecRef(); mbToken = false; meMultiline = MULTILINE_FALSE; + mbValueCached = true; break; default: mpToken = p; @@ -148,7 +152,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 ) @@ -213,6 +217,7 @@ void ScFormulaResult::SetDouble( double f ) mfValue = f; mbToken = false; meMultiline = MULTILINE_FALSE; + mbValueCached = true; } } @@ -327,6 +332,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; @@ -360,6 +371,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); @@ -416,6 +430,8 @@ FormulaError ScFormulaResult::GetResultError() const void ScFormulaResult::SetResultError( FormulaError nErr ) { mnError = nErr; + if (mnError != FormulaError::NONE) + mbValueCached = false; } formula::FormulaConstTokenRef ScFormulaResult::GetToken() const @@ -435,6 +451,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. @@ -526,6 +545,7 @@ void ScFormulaResult::SetHybridDouble( double f ) mfValue = f; mbToken = false; meMultiline = MULTILINE_FALSE; + mbValueCached = true; } } |