From 25d245deda19f31393642e3aa5084eaa04e78fa1 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 4 May 2016 10:09:32 -0700 Subject: [PATCH] Use erase-remove_if in RealmCoordinator::unregister_realm() --- src/impl/realm_coordinator.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/impl/realm_coordinator.cpp b/src/impl/realm_coordinator.cpp index a1e34f8c..3c624c32 100644 --- a/src/impl/realm_coordinator.cpp +++ b/src/impl/realm_coordinator.cpp @@ -152,17 +152,9 @@ RealmCoordinator::~RealmCoordinator() void RealmCoordinator::unregister_realm(Realm* realm) { std::lock_guard lock(m_realm_mutex); - for (size_t i = 0; i < m_weak_realm_notifiers.size(); ++i) { - auto& weak_realm_notifier = m_weak_realm_notifiers[i]; - if (!weak_realm_notifier.expired() && !weak_realm_notifier.is_for_realm(realm)) { - continue; - } - - if (i + 1 < m_weak_realm_notifiers.size()) { - weak_realm_notifier = std::move(m_weak_realm_notifiers.back()); - } - m_weak_realm_notifiers.pop_back(); - } + auto new_end = remove_if(begin(m_weak_realm_notifiers), end(m_weak_realm_notifiers), + [=](auto& notifier) { return notifier.expired() || notifier.is_for_realm(realm); }); + m_weak_realm_notifiers.erase(new_end, end(m_weak_realm_notifiers)); } void RealmCoordinator::clear_cache()