From e30e2ff278b8eb4122b6a0ccbf8146a25d5ad514 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 23 Nov 2015 14:46:51 -0800 Subject: [PATCH] Simplify RealmCoordinator::get_coordinator() --- src/impl/realm_coordinator.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/impl/realm_coordinator.cpp b/src/impl/realm_coordinator.cpp index f3d6c1d8..cf3289b4 100644 --- a/src/impl/realm_coordinator.cpp +++ b/src/impl/realm_coordinator.cpp @@ -33,17 +33,14 @@ static std::unordered_map> s_coordi std::shared_ptr RealmCoordinator::get_coordinator(StringData path) { std::lock_guard lock(s_coordinator_mutex); - std::shared_ptr coordinator; - auto it = s_coordinators_per_path.find(path); - if (it != s_coordinators_per_path.end()) { - coordinator = it->second.lock(); - } - - if (!coordinator) { - s_coordinators_per_path[path] = coordinator = std::make_shared(); + auto& weak_coordinator = s_coordinators_per_path[path]; + if (auto coordinator = weak_coordinator.lock()) { + return coordinator; } + auto coordinator = std::make_shared(); + weak_coordinator = coordinator; return coordinator; }