Skip to content

Commit 7853c8e

Browse files
generatedunixname1395027625275998meta-codesync[bot]
authored andcommitted
Cache persistenceId.str() in mcrouterGetCreate to avoid repeated string conversions
Reviewed By: sangongs Differential Revision: D118821640 fbshipit-source-id: a0368d548ed53e71ab7270788fede80ccac00ef3
1 parent e3371ce commit 7853c8e

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

mcrouter/McrouterManager.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,25 @@ class McrouterManager {
3636
const McrouterOptions& options,
3737
std::shared_ptr<folly::IOThreadPoolExecutorBase> ioThreadPool = nullptr) {
3838
std::shared_ptr<CarbonRouterInstanceBase> mcrouterBase;
39+
auto persistenceIdStr = persistenceId.str();
3940

4041
{
4142
std::lock_guard<std::mutex> lg(mutex_);
42-
mcrouterBase = folly::get_default(mcrouters_, persistenceId.str());
43+
mcrouterBase = folly::get_default(mcrouters_, persistenceIdStr);
4344
}
4445
if (!mcrouterBase) {
4546
std::lock_guard<std::mutex> ilg(initMutex_);
4647
{
4748
std::lock_guard<std::mutex> lg(mutex_);
48-
mcrouterBase = folly::get_default(mcrouters_, persistenceId.str());
49+
mcrouterBase = folly::get_default(mcrouters_, persistenceIdStr);
4950
}
5051
if (!mcrouterBase) {
5152
std::shared_ptr<CarbonRouterInstance<RouterInfo>> mcrouter =
5253
CarbonRouterInstance<RouterInfo>::create(
5354
options.clone(), std::move(ioThreadPool));
5455
if (mcrouter) {
5556
std::lock_guard<std::mutex> lg(mutex_);
56-
mcrouters_[persistenceId.str()] = mcrouter;
57+
mcrouters_[std::move(persistenceIdStr)] = mcrouter;
5758
return mcrouter.get();
5859
}
5960
}

0 commit comments

Comments
 (0)