From 1967792e020dedbd361eebb9ceee008b53ff097c Mon Sep 17 00:00:00 2001 From: Felix Raimundo Date: Thu, 14 Apr 2016 12:08:00 +0200 Subject: [PATCH] Replace a define in implementation to an attribute for context. Change-Id: I70b246c37c214d22079efd92c8b88f21206b87c9 --- poincare/include/poincare/context.h | 1 + poincare/src/context.cpp | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/poincare/include/poincare/context.h b/poincare/include/poincare/context.h index 8ce8fdb08..c29d3dac4 100644 --- a/poincare/include/poincare/context.h +++ b/poincare/include/poincare/context.h @@ -21,6 +21,7 @@ class Context { Expression * expression; }; ContextPair * m_pairs; + const uint16_t kMaxContextPairs = 10; }; #endif diff --git a/poincare/src/context.cpp b/poincare/src/context.cpp index 47b950150..40ac15209 100644 --- a/poincare/src/context.cpp +++ b/poincare/src/context.cpp @@ -2,10 +2,8 @@ #include #include -#define MAX_CONTEXT_PAIRS 10 - Context::Context() { - size_t size = sizeof(ContextPair)*MAX_CONTEXT_PAIRS; + size_t size = sizeof(ContextPair)*this->kMaxContextPairs; m_pairs = (ContextPair *)malloc(size); memset(m_pairs, 0, size); } @@ -15,7 +13,7 @@ Context::~Context() { } Expression * Context::operator[](const char * symbol_name) const { - for (int16_t i=0; ikMaxContextPairs; i++) { ContextPair p = m_pairs[i]; if (p.name != NULL && strcmp(p.name, symbol_name) == 0) { return p.expression; @@ -25,7 +23,7 @@ Expression * Context::operator[](const char * symbol_name) const { } void Context::setExpressionForSymbolName(Expression * expression, const char * symbol_name) { - for (int16_t i=0; ikMaxContextPairs; i++) { ContextPair * p = &m_pairs[i]; if (p->name == NULL) { // FIXME: Should be copied or retained!