Skip collecting change information when it isn't needed

This commit is contained in:
Thomas Goyne 2016-03-11 14:18:05 -08:00
parent e65ad4d413
commit b5bd00005c
6 changed files with 12 additions and 8 deletions

View File

@ -161,14 +161,16 @@ void BackgroundCollection::set_table(Table const& table)
void BackgroundCollection::add_required_change_info(TransactionChangeInfo& info) 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; auto max = *max_element(begin(m_relevant_tables), end(m_relevant_tables)) + 1;
if (max > info.tables_needed.size()) if (max > info.tables_needed.size())
info.tables_needed.resize(max, false); info.tables_needed.resize(max, false);
for (auto table_ndx : m_relevant_tables) { for (auto table_ndx : m_relevant_tables) {
info.tables_needed[table_ndx] = true; info.tables_needed[table_ndx] = true;
} }
do_add_required_change_info(info);
} }
void BackgroundCollection::prepare_handover() void BackgroundCollection::prepare_handover()

View File

@ -118,7 +118,7 @@ private:
virtual void do_detach_from(SharedGroup&) = 0; virtual void do_detach_from(SharedGroup&) = 0;
virtual void do_prepare_handover(SharedGroup&) = 0; virtual void do_prepare_handover(SharedGroup&) = 0;
virtual bool do_deliver(SharedGroup&) { return true; } 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; } virtual bool should_deliver_initial() const noexcept { return false; }
const std::thread::id m_thread_id = std::this_thread::get_id(); const std::thread::id m_thread_id = std::this_thread::get_id();

View File

@ -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); REALM_ASSERT(!m_lv_handover);
if (!m_lv) { 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(); 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}); info.lists.push_back({table.get_index_in_group(), row_ndx, m_col_ndx, &m_change});
m_info = &info; m_info = &info;
return true;
} }
void ListNotifier::run() void ListNotifier::run()

View File

@ -54,7 +54,7 @@ private:
void do_detach_from(SharedGroup& sg) override; void do_detach_from(SharedGroup& sg) override;
void release_data() noexcept override; void release_data() noexcept override;
void do_add_required_change_info(TransactionChangeInfo& info) override; bool do_add_required_change_info(TransactionChangeInfo& info) override;
}; };
} }
} }

View File

@ -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 // 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); REALM_ASSERT(m_query);
m_info = &info; m_info = &info;
return m_initial_run_complete && have_callbacks();
} }
void ResultsNotifier::run() void ResultsNotifier::run()

View File

@ -69,7 +69,7 @@ private:
void run() override; void run() override;
void do_prepare_handover(SharedGroup&) override; void do_prepare_handover(SharedGroup&) override;
bool do_deliver(SharedGroup& sg) 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 release_data() noexcept override;
void do_attach_to(SharedGroup& sg) override; void do_attach_to(SharedGroup& sg) override;