Small optimization to counter map management (#1382)

* Small optimization to counter map management

Avoids an unnecessary lookup.

* formatting
This commit is contained in:
Dominic Hamon 2022-04-07 14:37:22 +01:00 committed by GitHub
parent 3eac3b60d2
commit 74ae567294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,11 +118,13 @@ std::vector<BenchmarkReporter::Run> ComputeStats(
for (auto const& cnt : r.counters) {
auto it = counter_stats.find(cnt.first);
if (it == counter_stats.end()) {
counter_stats.insert({cnt.first, {cnt.second, std::vector<double>{}}});
it = counter_stats.find(cnt.first);
it = counter_stats
.emplace(cnt.first,
CounterStat{cnt.second, std::vector<double>{}})
.first;
it->second.s.reserve(reports.size());
} else {
BM_CHECK_EQ(counter_stats[cnt.first].c.flags, cnt.second.flags);
BM_CHECK_EQ(it->second.c.flags, cnt.second.flags);
}
}
}