Performance improvement of setVar action

This commit is contained in:
Felipe Zimmerle 2015-10-15 14:03:43 -03:00
parent e57ee8908f
commit 3351338551

View File

@ -101,12 +101,26 @@ void SetVar::dump() {
bool SetVar::evaluate(Rule *rule, Assay *assay) { bool SetVar::evaluate(Rule *rule, Assay *assay) {
std::string targetValue; std::string targetValue;
variableName = MacroExpansion::expand(variableName, assay);
int value = 0; int 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 {
pre = stoi(resolvedPre);
} catch (...) {
pre = 0;
}
try { try {
std::string *resolvedValue = std::string *resolvedValue =
assay->resolve_variable_first(collectionName, variableName); assay->resolve_variable_first(collectionName,
variableNameExpanded);
if (resolvedValue == NULL) { if (resolvedValue == NULL) {
value = 0; value = 0;
} else { } else {
@ -116,18 +130,6 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
value = 0; value = 0;
} }
std::string resolvedPre = MacroExpansion::expand(predicate, assay);
if (operation == setOperation) {
targetValue = resolvedPre;
} else {
int pre = 0;
try {
pre = stoi(resolvedPre);
} catch (...) {
pre = 0;
}
switch (operation) { switch (operation) {
case sumAndSetOperation: case sumAndSetOperation:
targetValue = std::to_string(value + pre); targetValue = std::to_string(value + pre);
@ -135,17 +137,14 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
case substractAndSetOperation: case substractAndSetOperation:
targetValue = std::to_string(value - pre); targetValue = std::to_string(value - pre);
break; break;
case setToOne:
targetValue = std::string("1");
break;
} }
} }
#ifndef NO_LOGS #ifndef NO_LOGS
assay->debug(8, "Saving variable: " + collectionName + ":" + \ assay->debug(8, "Saving variable: " + collectionName + ":" + \
variableName + " with value: " + targetValue); variableNameExpanded + " with value: " + targetValue);
#endif #endif
assay->setCollection(collectionName, variableName, targetValue); assay->setCollection(collectionName, variableNameExpanded, targetValue);
return true; return true;
} }