sc/inc/formularesult.hxx | 2 + sc/source/core/data/formulacell.cxx | 10 ------- sc/source/core/tool/formularesult.cxx | 45 ++++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 11 deletions(-)
New commits: commit 6ff3d0a234635455b9665d9925c609d793ea3185 Author: Kohei Yoshida <kohei.yosh...@gmail.com> Date: Mon Jun 24 21:33:40 2013 -0400 Avoid redundant calls to GetCellResultType(). Change-Id: I105b9f555037b1750af6aaff6fc10d2301afde7c diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx index a88f82d..6736a10 100644 --- a/sc/inc/formularesult.hxx +++ b/sc/inc/formularesult.hxx @@ -132,6 +132,8 @@ public: one paragraph */ bool IsMultiline() const; + bool GetErrorOrDouble( sal_uInt16& rErr, double& rVal ) const; + /** Get error code if set or GetCellResultType() is formula::svError or svUnknown, else 0. */ sal_uInt16 GetResultError() const; diff --git a/sc/source/core/data/formulacell.cxx b/sc/source/core/data/formulacell.cxx index 15652b5..e554df4 100644 --- a/sc/source/core/data/formulacell.cxx +++ b/sc/source/core/data/formulacell.cxx @@ -1942,15 +1942,7 @@ bool ScFormulaCell::GetErrorOrValue( sal_uInt16& rErr, double& rVal ) if (rErr) return true; - rErr = aResult.GetResultError(); - if (rErr) - return true; - - if (!aResult.IsValue()) - return false; - - rVal = aResult.GetDouble(); - return true; + return aResult.GetErrorOrDouble(rErr, rVal); } bool ScFormulaCell::HasOneReference( ScRange& r ) const diff --git a/sc/source/core/tool/formularesult.cxx b/sc/source/core/tool/formularesult.cxx index a7c70e6..a106e5f 100644 --- a/sc/source/core/tool/formularesult.cxx +++ b/sc/source/core/tool/formularesult.cxx @@ -249,13 +249,21 @@ bool ScFormulaResult::IsEmptyDisplayedAsString() const return false; } -bool ScFormulaResult::IsValue() const +namespace { + +inline bool isValue( formula::StackVar sv ) { - formula::StackVar sv = GetCellResultType(); return sv == formula::svDouble || sv == formula::svError || sv == formula::svEmptyCell || sv == formula::svHybridValueCell; } +} + +bool ScFormulaResult::IsValue() const +{ + return isValue(GetCellResultType()); +} + bool ScFormulaResult::IsMultiline() const { if (meMultiline == MULTILINE_UNKNOWN) @@ -269,6 +277,39 @@ bool ScFormulaResult::IsMultiline() const return meMultiline == MULTILINE_TRUE; } +bool ScFormulaResult::GetErrorOrDouble( sal_uInt16& rErr, double& rVal ) const +{ + if (mnError) + { + rErr = mnError; + return true; + } + + formula::StackVar sv = GetCellResultType(); + if (sv == formula::svError) + { + if (GetType() == formula::svMatrixCell) + { + // don't need to test for mpToken here, GetType() already did it + rErr = static_cast<const ScMatrixCellResultToken*>(mpToken)-> + GetUpperLeftToken()->GetError(); + } + else if (mpToken) + { + rErr = mpToken->GetError(); + } + } + + if (rErr) + return true; + + if (!isValue(sv)) + return false; + + rVal = GetDouble(); + return true; +} + sal_uInt16 ScFormulaResult::GetResultError() const { if (mnError) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits