From 924e235ba8ce0bbcc22dc395c4edb0178c909db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 6 Jul 2020 17:16:22 +0200 Subject: [PATCH] [apps/calculation] Factorize some code --- apps/calculation/calculation.cpp | 12 ++++++++---- apps/calculation/calculation.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index 7a7a9e425..236f59ed0 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -41,8 +41,7 @@ Calculation * Calculation::next() const { void Calculation::tidy() { /* Reset height memoization (the complex format could have changed when * re-entering Calculation app which would impact the heights). */ - m_height = -1; - m_expandedHeight = -1; + resetHeightMemoization(); } const char * Calculation::approximateOutputText(NumberOfSignificantDigits numberOfSignificantDigits) const { @@ -193,9 +192,9 @@ Calculation::DisplayOutput Calculation::displayOutput(Context * context) { void Calculation::forceDisplayOutput(DisplayOutput d) { m_displayOutput = d; // Reset heights memoization as it might have changed when we modify the display output - m_height = -1; - m_expandedHeight = -1; + resetHeightMemoization(); } + bool Calculation::shouldOnlyDisplayExactOutput() { /* If the input is a "store in a function", do not display the approximate * result. This prevents x->f(x) from displaying x = undef. */ @@ -290,4 +289,9 @@ Calculation::AdditionalInformationType Calculation::additionalInformationType(Co return AdditionalInformationType::None; } +void Calculation::resetHeightMemoization() { + m_height = -1; + m_expandedHeight = -1; +} + } diff --git a/apps/calculation/calculation.h b/apps/calculation/calculation.h index dc1646657..a09253abc 100644 --- a/apps/calculation/calculation.h +++ b/apps/calculation/calculation.h @@ -99,6 +99,7 @@ private: static constexpr int k_numberOfExpressions = 4; static constexpr KDCoordinate k_heightComputationFailureHeight = 50; static constexpr const char * k_maximalIntegerWithAdditionalInformation = "10000000000000000"; + void resetHeightMemoization(); /* Buffers holding text expressions have to be longer than the text written * by user (of maximum length TextField::maxBufferSize()) because when we * print an expression we add omitted signs (multiplications, parenthesis...) */