diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-24 21:33:40 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-06-27 15:47:53 -0400 |
commit | 884528f06abcec239a67e064092003f343c966c2 (patch) | |
tree | f88360de55163d0ced23d2156719d9cfb959f318 /sc | |
parent | f5357308c4f8823836ebd17dd24c51729322be32 (diff) |
Avoid redundant calls to GetCellResultType().
Change-Id: I105b9f555037b1750af6aaff6fc10d2301afde7c
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/formularesult.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/formulacell.cxx | 10 | ||||
-rw-r--r-- | sc/source/core/tool/formularesult.cxx | 45 |
3 files changed, 46 insertions, 11 deletions
diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx index a88f82de0705..6736a10fc1cb 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 463bf4ad1a8a..ae3cb2d90095 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 a7c70e64b8d6..a106e5f9db76 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) |