[apps/calculation] Invalid calculation height memoization when leaving

the app.

Fix wrong memoization: in calculation app input '[[1+i, 2][3,4]]', change
the complex format to Polar, go back to the calculation app --> the
calculation height was no recomputed despite the fact that the approximation
output changed.
This commit is contained in:
Émilie Feral
2019-08-19 09:59:01 +02:00
parent 05972099fe
commit 1cc09de9ae
4 changed files with 17 additions and 1 deletions

View File

@@ -33,6 +33,13 @@ Calculation * Calculation::next() const {
return reinterpret_cast<Calculation *>(const_cast<char *>(result));
}
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;
}
const char * Calculation::approximateOutputText() const {
const char * exactOutput = exactOutputText();
return exactOutput + strlen(exactOutput) + 1;

View File

@@ -50,6 +50,8 @@ public:
bool operator==(const Calculation& c);
Calculation * next() const;
void tidy();
// Texts
const char * inputText() const { return m_inputText; }
const char * exactOutputText() const { return m_inputText + strlen(m_inputText) + 1; }

View File

@@ -141,6 +141,13 @@ void CalculationStore::deleteAll() {
resetMemoizedModelsAfterCalculationIndex(-1);
}
void CalculationStore::tidy() {
resetMemoizedModelsAfterCalculationIndex(-1);
for (Calculation * c : *this) {
c->tidy();
}
}
Expression CalculationStore::ansExpression(Context * context) {
if (numberOfCalculations() == 0) {
return Rational::Builder(0);

View File

@@ -32,7 +32,7 @@ public:
void deleteAll();
int numberOfCalculations() const { return m_numberOfCalculations; }
Poincare::Expression ansExpression(Poincare::Context * context);
void tidy() { resetMemoizedModelsAfterCalculationIndex(-1); }
void tidy();
private:
static constexpr int k_bufferSize = 10 * 3 * Constant::MaxSerializedExpressionSize;