[apps/shared] Cache lookup on function evaluation

When evaluating a ContinuousFunction for a float value, the function
will first try to ask its cache (if it has been filled beforehand).

Change-Id: I519d2d3dcf344ba63e30a0f011db2306c7141315
This commit is contained in:
Gabriel Ozouf
2020-06-09 14:05:15 +02:00
committed by Émilie Feral
parent a9c633a540
commit c70b545ba1
2 changed files with 15 additions and 1 deletions

View File

@@ -351,6 +351,18 @@ Poincare::Expression ContinuousFunction::sumBetweenBounds(double start, double e
* the derivative table. */
}
Poincare::Coordinate2D<float> ContinuousFunction::checkForCacheHitAndEvaluate(float t, Poincare::Context * context) const {
Poincare::Coordinate2D<float> res(NAN, NAN);
if (cache()->filled()) {
res = cache()->valueForParameter(this, t);
}
if (std::isnan(res.x1()) || std::isnan(res.x2())) {
res = privateEvaluateXYAtParameter(t, context);
//res = Poincare::Coordinate2D<float>(privateEvaluateXYAtParameter(t, context).x1(), 0);
}
return res;
}
Ion::Storage::Record::ErrorStatus ContinuousFunction::setContent(const char * c, Poincare::Context * context) {
cache()->clear();
return ExpressionModelHandle::setContent(c, context);