[apps/shared/function_graph_controller] Do not compute the numberOfActiveFunctions repeatedly

This commit is contained in:
Ruben Dashyan
2020-01-31 15:24:34 +01:00
committed by Léa Saviot
parent 503a9ed128
commit 1cdd61ea47

View File

@@ -135,6 +135,7 @@ FunctionStore * FunctionGraphController::functionStore() const {
void FunctionGraphController::initCursorParameters() {
Poincare::Context * context = textFieldDelegateApp()->localContext();
const int activeFunctionsCount = functionStore()->numberOfActiveFunctions();
int functionIndex = 0;
Coordinate2D<double> xy;
double t;
@@ -143,7 +144,7 @@ void FunctionGraphController::initCursorParameters() {
ExpiringPointer<Function> firstFunction = functionStore()->modelForRecord(record);
t = defaultCursorT(record);
xy = firstFunction->evaluateXYAtParameter(t, context);
} while ((std::isnan(xy.x2()) || std::isinf(xy.x2())) && functionIndex < functionStore()->numberOfActiveFunctions());
} while ((std::isnan(xy.x2()) || std::isinf(xy.x2())) && functionIndex < activeFunctionsCount);
m_cursor->moveTo(t, xy.x1(), xy.x2());
functionIndex = (std::isnan(xy.x2()) || std::isinf(xy.x2())) ? 0 : functionIndex - 1;
selectFunctionWithCursor(functionIndex);