From a9c633a54048b0c3499e5de8e58db40a9ba2080d Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Tue, 9 Jun 2020 14:00:11 +0200 Subject: [PATCH] [apps/shared] Functions cache clears on change Added several triggers to clear the cache when the function's type, range or content is changed. Change-Id: I4f49a90bb6571e335a4a601723d7715b8de1e25e --- apps/shared/continuous_function.cpp | 9 +++++++++ apps/shared/continuous_function.h | 1 + apps/shared/expression_model_handle.h | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/shared/continuous_function.cpp b/apps/shared/continuous_function.cpp index ebac4e160..042e42ea6 100644 --- a/apps/shared/continuous_function.cpp +++ b/apps/shared/continuous_function.cpp @@ -125,6 +125,8 @@ void ContinuousFunction::setPlotType(PlotType newPlotType, Poincare::Preferences recordData()->setPlotType(newPlotType); + cache()->clear(); + // Recompute the layouts m_model.tidy(); @@ -251,10 +253,12 @@ float ContinuousFunction::tMax() const { void ContinuousFunction::setTMin(float tMin) { recordData()->setTMin(tMin); + cache()->clear(); } void ContinuousFunction::setTMax(float tMax) { recordData()->setTMax(tMax); + cache()->clear(); } void * ContinuousFunction::Model::expressionAddress(const Ion::Storage::Record * record) const { @@ -347,6 +351,11 @@ Poincare::Expression ContinuousFunction::sumBetweenBounds(double start, double e * the derivative table. */ } +Ion::Storage::Record::ErrorStatus ContinuousFunction::setContent(const char * c, Poincare::Context * context) { + cache()->clear(); + return ExpressionModelHandle::setContent(c, context); +} + template Coordinate2D ContinuousFunction::templatedApproximateAtParameter(float, Poincare::Context *) const; template Coordinate2D ContinuousFunction::templatedApproximateAtParameter(double, Poincare::Context *) const; diff --git a/apps/shared/continuous_function.h b/apps/shared/continuous_function.h index 096d6ee61..86769eca9 100644 --- a/apps/shared/continuous_function.h +++ b/apps/shared/continuous_function.h @@ -80,6 +80,7 @@ public: // Cache ContinuousFunctionCache * cache() const { return const_cast(&m_cache); } + Ion::Storage::Record::ErrorStatus setContent(const char * c, Poincare::Context * context) override; private: constexpr static float k_polarParamRangeSearchNumberOfPoints = 100.0f; // This is ad hoc, no special justification typedef Poincare::Coordinate2D (*ComputePointOfInterest)(Poincare::Expression e, char * symbol, double start, double step, double max, Poincare::Context * context); diff --git a/apps/shared/expression_model_handle.h b/apps/shared/expression_model_handle.h index b07c18e36..8d6229a18 100644 --- a/apps/shared/expression_model_handle.h +++ b/apps/shared/expression_model_handle.h @@ -30,7 +30,7 @@ public: * behaviour but it is not true for its child classes (for example, in * Sequence). */ virtual void tidy() { model()->tidy(); } - Ion::Storage::Record::ErrorStatus setContent(const char * c, Poincare::Context * context) { return editableModel()->setContent(this, c, context, symbol()); } + virtual Ion::Storage::Record::ErrorStatus setContent(const char * c, Poincare::Context * context) { return editableModel()->setContent(this, c, context, symbol()); } Ion::Storage::Record::ErrorStatus setExpressionContent(const Poincare::Expression & e) { return editableModel()->setExpressionContent(this, e); } protected: ExpressionModel * editableModel() { return const_cast(model()); }