From b5bd00005c8d4ec1c05d49cdf491454f63f8ebee Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 11 Mar 2016 14:18:05 -0800 Subject: [PATCH] Skip collecting change information when it isn't needed --- src/impl/background_collection.cpp | 6 ++++-- src/impl/background_collection.hpp | 2 +- src/impl/list_notifier.cpp | 5 +++-- src/impl/list_notifier.hpp | 2 +- src/impl/results_notifier.cpp | 3 ++- src/impl/results_notifier.hpp | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/impl/background_collection.cpp b/src/impl/background_collection.cpp index 5ce39b45..b1d4dec9 100644 --- a/src/impl/background_collection.cpp +++ b/src/impl/background_collection.cpp @@ -161,14 +161,16 @@ void BackgroundCollection::set_table(Table const& table) void BackgroundCollection::add_required_change_info(TransactionChangeInfo& info) { + if (!do_add_required_change_info(info)) { + return; + } + auto max = *max_element(begin(m_relevant_tables), end(m_relevant_tables)) + 1; if (max > info.tables_needed.size()) info.tables_needed.resize(max, false); for (auto table_ndx : m_relevant_tables) { info.tables_needed[table_ndx] = true; } - - do_add_required_change_info(info); } void BackgroundCollection::prepare_handover() diff --git a/src/impl/background_collection.hpp b/src/impl/background_collection.hpp index 78da5124..162e0047 100644 --- a/src/impl/background_collection.hpp +++ b/src/impl/background_collection.hpp @@ -118,7 +118,7 @@ private: virtual void do_detach_from(SharedGroup&) = 0; virtual void do_prepare_handover(SharedGroup&) = 0; virtual bool do_deliver(SharedGroup&) { return true; } - virtual void do_add_required_change_info(TransactionChangeInfo&) { } + virtual bool do_add_required_change_info(TransactionChangeInfo&) { return true; } virtual bool should_deliver_initial() const noexcept { return false; } const std::thread::id m_thread_id = std::this_thread::get_id(); diff --git a/src/impl/list_notifier.cpp b/src/impl/list_notifier.cpp index e8291fad..fd6a4ffe 100644 --- a/src/impl/list_notifier.cpp +++ b/src/impl/list_notifier.cpp @@ -69,11 +69,11 @@ void ListNotifier::do_detach_from(SharedGroup& sg) } } -void ListNotifier::do_add_required_change_info(TransactionChangeInfo& info) +bool ListNotifier::do_add_required_change_info(TransactionChangeInfo& info) { REALM_ASSERT(!m_lv_handover); if (!m_lv) { - return; // origin row was deleted after the notification was added + return false; // origin row was deleted after the notification was added } size_t row_ndx = m_lv->get_origin_row_index(); @@ -81,6 +81,7 @@ void ListNotifier::do_add_required_change_info(TransactionChangeInfo& info) info.lists.push_back({table.get_index_in_group(), row_ndx, m_col_ndx, &m_change}); m_info = &info; + return true; } void ListNotifier::run() diff --git a/src/impl/list_notifier.hpp b/src/impl/list_notifier.hpp index ef3805bf..9cc0d775 100644 --- a/src/impl/list_notifier.hpp +++ b/src/impl/list_notifier.hpp @@ -54,7 +54,7 @@ private: void do_detach_from(SharedGroup& sg) override; void release_data() noexcept override; - void do_add_required_change_info(TransactionChangeInfo& info) override; + bool do_add_required_change_info(TransactionChangeInfo& info) override; }; } } diff --git a/src/impl/results_notifier.cpp b/src/impl/results_notifier.cpp index 282adb16..de1ce338 100644 --- a/src/impl/results_notifier.cpp +++ b/src/impl/results_notifier.cpp @@ -71,10 +71,11 @@ static bool map_moves(size_t& idx, CollectionChangeIndices const& changes) // // Separately from the handover data flow, m_target_results is guarded by the target lock -void ResultsNotifier::do_add_required_change_info(TransactionChangeInfo& info) +bool ResultsNotifier::do_add_required_change_info(TransactionChangeInfo& info) { REALM_ASSERT(m_query); m_info = &info; + return m_initial_run_complete && have_callbacks(); } void ResultsNotifier::run() diff --git a/src/impl/results_notifier.hpp b/src/impl/results_notifier.hpp index 96cb0a38..2482b770 100644 --- a/src/impl/results_notifier.hpp +++ b/src/impl/results_notifier.hpp @@ -69,7 +69,7 @@ private: void run() override; void do_prepare_handover(SharedGroup&) override; bool do_deliver(SharedGroup& sg) override; - void do_add_required_change_info(TransactionChangeInfo& info) override; + bool do_add_required_change_info(TransactionChangeInfo& info) override; void release_data() noexcept override; void do_attach_to(SharedGroup& sg) override;