diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-04 13:49:05 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-04 15:35:35 +0200 |
commit | 44137151dfd719ed921aece504eb11c5e098492c (patch) | |
tree | 8e3b24f767ee6bdc36fd1efaa973a96b1113a9f9 /sc | |
parent | e73825ea4b12cc62caa95faa902bfc9ebb48f58a (diff) |
simplify ScChartListenerCollection listener management
Change-Id: I95961bc77b5f07c9eb57675ce2cada79fec4a2e2
Reviewed-on: https://gerrit.libreoffice.org/56942
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/tool/chartlis.cxx | 86 |
1 files changed, 19 insertions, 67 deletions
diff --git a/sc/source/core/tool/chartlis.cxx b/sc/source/core/tool/chartlis.cxx index 6c853fcb2166..06d1f36c0fe3 100644 --- a/sc/source/core/tool/chartlis.cxx +++ b/sc/source/core/tool/chartlis.cxx @@ -477,60 +477,31 @@ void ScChartListenerCollection::ChangeListening( const OUString& rName, pCL->StartListeningTo(); } -namespace { - -class InsertChartListener -{ - ScChartListenerCollection::ListenersType& mrListeners; -public: - explicit InsertChartListener(ScChartListenerCollection::ListenersType& rListeners) : - mrListeners(rListeners) {} - - void operator() (ScChartListener* p) - { - OUString aName = p->GetName(); - mrListeners.insert(std::make_pair(aName, std::unique_ptr<ScChartListener>(p))); - } -}; - -} - void ScChartListenerCollection::FreeUnused() { if (meModifiedDuringUpdate == SC_CLCUPDATE_RUNNING) meModifiedDuringUpdate = SC_CLCUPDATE_MODIFIED; - ListenersType aUsed, aUnused; + ListenersType aUsed; - // First, filter each listener into 'used' and 'unused' categories. + for (auto & pair : m_Listeners) { - while (!m_Listeners.empty()) + ScChartListener* p = pair.second.get(); + if (p->IsUno()) { - std::unique_ptr<ScChartListener> p(std::move(m_Listeners.begin()->second)); - if (p->IsUno()) - { - // We don't delete UNO charts; they are to be deleted separately via FreeUno(). - aUsed.insert(std::make_pair(m_Listeners.begin()->first, std::move(p))); - m_Listeners.erase(m_Listeners.begin()); - continue; - } - - if (p->IsUsed()) - { - p->SetUsed(false); - aUsed.insert(std::make_pair(m_Listeners.begin()->first, std::move(p))); - m_Listeners.erase(m_Listeners.begin()); - } - else - { - aUnused.insert(std::make_pair(m_Listeners.begin()->first, std::move(p))); - m_Listeners.erase(m_Listeners.begin()); - } + // We don't delete UNO charts; they are to be deleted separately via FreeUno(). + aUsed.insert(std::make_pair(pair.first, std::move(pair.second))); + continue; + } + if (p->IsUsed()) + { + p->SetUsed(false); + aUsed.insert(std::make_pair(pair.first, std::move(pair.second))); } } - std::swap(aUsed, m_Listeners); + m_Listeners = std::move(aUsed); } void ScChartListenerCollection::FreeUno( const uno::Reference< chart::XChartDataChangeEventListener >& rListener, @@ -539,33 +510,14 @@ void ScChartListenerCollection::FreeUno( const uno::Reference< chart::XChartData if (meModifiedDuringUpdate == SC_CLCUPDATE_RUNNING) meModifiedDuringUpdate = SC_CLCUPDATE_MODIFIED; - std::vector<ScChartListener*> aUsed, aUnused; - - // First, filter each listener into 'used' and 'unused' categories. - { - for (auto const& it : m_Listeners) - { - ScChartListener *const p = it.second.get(); - if (p->IsUno() && p->GetUnoListener() == rListener && p->GetUnoSource() == rSource) - aUnused.push_back(p); - else - aUsed.push_back(p); - } - } - - // Release all pointers currently managed by the ptr_map container. - // coverity[leaked_storage] - no leak, because we will take care of them below - for (auto & it : m_Listeners) + for (auto it = m_Listeners.begin(); it != m_Listeners.end(); ) { - it.second.release(); + ScChartListener *const p = it->second.get(); + if (p->IsUno() && p->GetUnoListener() == rListener && p->GetUnoSource() == rSource) + it = m_Listeners.erase(it); + else + ++it; } - m_Listeners.clear(); - - // Re-insert the listeners we need to keep. - std::for_each(aUsed.begin(), aUsed.end(), InsertChartListener(m_Listeners)); - - // Now, delete the ones no longer needed. - std::for_each(aUnused.begin(), aUnused.end(), std::default_delete<ScChartListener>()); } void ScChartListenerCollection::StartTimer() |