sc/inc/formularesult.hxx | 2 ++ sc/source/core/tool/formularesult.cxx | 28 ++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-)
New commits: commit 77f7b4768a79e5a8489b163670e0ce10fbd07c49 Author: Dennis Francis <dennis.fran...@collabora.co.uk> AuthorDate: Wed Jul 11 17:19:28 2018 +0530 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Thu Aug 23 11:28:23 2018 +0200 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.lu...@collabora.com> diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx index b5fd6228dc41..eac70db65831 100644 --- a/sc/inc/formularesult.hxx +++ b/sc/inc/formularesult.hxx @@ -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 */ diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx index 30f8a736852d..4387af07511e 100644 --- a/sc/source/core/tool/formularesult.cxx +++ b/sc/source/core/tool/formularesult.cxx @@ -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; } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits