From 74ae5672945e713135a7f47fb26bd14d63488f4f Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Thu, 7 Apr 2022 14:37:22 +0100 Subject: [PATCH] Small optimization to counter map management (#1382) * Small optimization to counter map management Avoids an unnecessary lookup. * formatting --- src/statistics.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/statistics.cc b/src/statistics.cc index 3e5ef099..5ba885ab 100644 --- a/src/statistics.cc +++ b/src/statistics.cc @@ -118,11 +118,13 @@ std::vector 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{}}}); - it = counter_stats.find(cnt.first); + it = counter_stats + .emplace(cnt.first, + CounterStat{cnt.second, std::vector{}}) + .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); } } }