Skip to content

Commit

Permalink
Avoid double lookups on the hot path
Browse files Browse the repository at this point in the history
No effect on my naive benchmark.
  • Loading branch information
simonlindholm authored and eldering committed Oct 20, 2019
1 parent a49b48e commit 4bd35d9
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libchecktestdata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,14 @@ value_t getvar(const expr& var, int use_preset = 0)
if ( gendata && preset.count(var.val) && preset[var.val].count(ind) ) {
return preset[var.val][ind];
}
if ( variable.count(var.val) && variable[var.val].count(ind) ) {
return variable[var.val][ind];
// Avoid double lookups on the hot path
auto it = variable.find(var.val);
if (it != variable.end()) {
auto& map = it->second;
auto it2 = map.find(ind);
if (it2 != map.end()) {
return it2->second;
}
}
}
cerr << "variable " << var << " undefined in " << program[prognr] << endl;
Expand Down

0 comments on commit 4bd35d9

Please sign in to comment.