diff --git a/apps/calculation/calculation_store.cpp b/apps/calculation/calculation_store.cpp index b93b0e203..254875dc0 100644 --- a/apps/calculation/calculation_store.cpp +++ b/apps/calculation/calculation_store.cpp @@ -20,16 +20,17 @@ Calculation * CalculationStore::push(Calculation * c) { Calculation * CalculationStore::calculationAtIndex(int i) { int j = 0; Calculation * currentCalc = m_start; - while (j<=i) { + Calculation * previousCalc = nullptr; + while (j <= i) { + if (!currentCalc++->isEmpty()) { + previousCalc = currentCalc - 1; + j++; + } if (currentCalc >= m_calculations + k_maxNumberOfCalculations) { currentCalc = m_calculations; } - if (!currentCalc->isEmpty()) { - j++; - } - currentCalc++; } - return currentCalc-1; + return previousCalc; } int CalculationStore::numberOfCalculations() { diff --git a/apps/calculation/calculation_store.h b/apps/calculation/calculation_store.h index 4d67ef4fc..fb8ee15e7 100644 --- a/apps/calculation/calculation_store.h +++ b/apps/calculation/calculation_store.h @@ -5,6 +5,8 @@ namespace Calculation { +// TODO: make tests for the ring buffer + class CalculationStore { public: CalculationStore();