Skip to content

Commit 379eaed

Browse files
ttsugriyfacebook-github-bot
authored andcommitted
Avoid counter name copies.
Summary: 1) there's no need to copy string before passing it to `insert` 2) it's inefficient and unnecessary to create a pair and pass it to `insert` instead of passing key and value to `emplace` so that they can be used directly Reviewed By: dmm-fb Differential Revision: D75711421 fbshipit-source-id: 5fe8020f2034af699c8867d98a426508cc78fa02
1 parent b3be105 commit 379eaed

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

fb303/ServiceData.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,8 @@ int64_t ServiceData::getCounter(StringPiece key) const {
372372
void ServiceData::getCounters(map<string, int64_t>& _return) const {
373373
{
374374
auto countersRLock = counters_.rlock();
375-
for (auto const& elem : countersRLock->map) {
376-
_return.insert(std::make_pair(
377-
std::string(elem.first),
378-
elem.second.load(std::memory_order_relaxed)));
375+
for (auto const& [name, value] : countersRLock->map) {
376+
_return.emplace(name, value.load(std::memory_order_relaxed));
379377
}
380378
}
381379

0 commit comments

Comments
 (0)