Huge performance improvement: passing variables as pointers avoiding copies

This commit is contained in:
Felipe Zimmerle
2015-09-18 20:21:12 -03:00
parent 2451bf05d7
commit 076a02951c
45 changed files with 207 additions and 208 deletions

View File

@@ -32,34 +32,33 @@ namespace actions {
bool Capture::evaluate(Rule *rule, Assay *assay) {
operators::Operator *op = rule->op;
std::list<std::string> match;
std::list<std::string> *match;
operators::Pm *pm = dynamic_cast<operators::Pm *>(op);
if (pm != NULL) {
match = pm->matched;
match = &pm->matched;
}
operators::Rx *rx = dynamic_cast<operators::Rx *>(op);
if (rx != NULL) {
match = rx->matched;
match = &rx->matched;
}
operators::Contains *contains = dynamic_cast<operators::Contains *>(op);
if (contains != NULL) {
match = contains->matched;
match = &contains->matched;
}
if (match.empty()) {
if (match->empty()) {
return false;
}
int i = 0;
while (match.empty() == false) {
assay->setCollection("TX", std::to_string(i), match.back());
match.pop_back();
while (match->empty() == false) {
assay->setCollection("TX", std::to_string(i), match->back());
match->pop_back();
i++;
}
return true;
}

View File

@@ -116,30 +116,29 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
value = 0;
}
int pre = 0;
try {
pre = stoi(predicate);
} catch (...) {
std::string resolvedPre = MacroExpansion::expand(predicate, assay);
if (operation == setOperation) {
targetValue = resolvedPre;
} else {
int pre = 0;
try {
pre = stoi(MacroExpansion::expand(predicate, assay));
pre = stoi(resolvedPre);
} catch (...) {
pre = 0;
}
}
switch (operation) {
case setOperation:
targetValue = MacroExpansion::expand(predicate, assay);
break;
case sumAndSetOperation:
targetValue = std::to_string(value + pre);
break;
case substractAndSetOperation:
targetValue = std::to_string(value - pre);
break;
case setToOne:
targetValue = std::string("1");
break;
switch (operation) {
case sumAndSetOperation:
targetValue = std::to_string(value + pre);
break;
case substractAndSetOperation:
targetValue = std::to_string(value - pre);
break;
case setToOne:
targetValue = std::string("1");
break;
}
}
#ifndef NO_LOGS

View File

@@ -35,24 +35,18 @@ namespace transformations {
std::string RemoveNulls::evaluate(std::string value,
Assay *assay) {
int64_t i, j;
int64_t i;
char *input = reinterpret_cast<char *>(malloc(value.size()
* sizeof(char)));
memcpy(input, value.c_str(), value.size());
std::string ret;
i = j = 0;
i = 0;
while (i < value.size()) {
if (input[i] != '\0') {
input[j] = input[i];
j++;
if (value.at(i) != '\0') {
ret += value.at(i);
}
i++;
}
std::string ret(input, 0, j);
free(input);
return ret;
}