Simplify RealmCoordinator::get_coordinator()

This commit is contained in:
Thomas Goyne 2015-11-23 14:46:51 -08:00
parent 7a0c83929f
commit e30e2ff278
1 changed files with 5 additions and 8 deletions

View File

@ -33,17 +33,14 @@ static std::unordered_map<std::string, std::weak_ptr<RealmCoordinator>> s_coordi
std::shared_ptr<RealmCoordinator> RealmCoordinator::get_coordinator(StringData path)
{
std::lock_guard<std::mutex> lock(s_coordinator_mutex);
std::shared_ptr<RealmCoordinator> 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<RealmCoordinator>();
auto& weak_coordinator = s_coordinators_per_path[path];
if (auto coordinator = weak_coordinator.lock()) {
return coordinator;
}
auto coordinator = std::make_shared<RealmCoordinator>();
weak_coordinator = coordinator;
return coordinator;
}