From 3351338551ad062a41a1bc2a64693b083ca030fd Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Thu, 15 Oct 2015 14:03:43 -0300 Subject: [PATCH] Performance improvement of setVar action --- src/actions/set_var.cc | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/actions/set_var.cc b/src/actions/set_var.cc index 89d990b8..b45f9523 100644 --- a/src/actions/set_var.cc +++ b/src/actions/set_var.cc @@ -101,25 +101,14 @@ void SetVar::dump() { bool SetVar::evaluate(Rule *rule, Assay *assay) { std::string targetValue; - - variableName = MacroExpansion::expand(variableName, assay); int value = 0; - try { - std::string *resolvedValue = - assay->resolve_variable_first(collectionName, variableName); - if (resolvedValue == NULL) { - value = 0; - } else { - value = stoi(*resolvedValue); - } - } catch (...) { - value = 0; - } - - + std::string variableNameExpanded = MacroExpansion::expand(variableName, assay); std::string resolvedPre = MacroExpansion::expand(predicate, assay); + if (operation == setOperation) { targetValue = resolvedPre; + } else if (operation == setToOne) { + targetValue = std::string("1"); } else { int pre = 0; try { @@ -128,6 +117,19 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) { pre = 0; } + try { + std::string *resolvedValue = + assay->resolve_variable_first(collectionName, + variableNameExpanded); + if (resolvedValue == NULL) { + value = 0; + } else { + value = stoi(*resolvedValue); + } + } catch (...) { + value = 0; + } + switch (operation) { case sumAndSetOperation: targetValue = std::to_string(value + pre); @@ -135,17 +137,14 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) { case substractAndSetOperation: targetValue = std::to_string(value - pre); break; - case setToOne: - targetValue = std::string("1"); - break; } } #ifndef NO_LOGS assay->debug(8, "Saving variable: " + collectionName + ":" + \ - variableName + " with value: " + targetValue); + variableNameExpanded + " with value: " + targetValue); #endif - assay->setCollection(collectionName, variableName, targetValue); + assay->setCollection(collectionName, variableNameExpanded, targetValue); return true; }