[Libreoffice-commits] core.git: sc/source

Noel Grandin noel.grandin at collabora.co.uk
Wed Jul 4 13:36:03 UTC 2018


 sc/source/core/tool/chartlis.cxx |   86 ++++++++-------------------------------
 1 file changed, 19 insertions(+), 67 deletions(-)

New commits:
commit 44137151dfd719ed921aece504eb11c5e098492c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed Jul 4 13:49:05 2018 +0200

    simplify ScChartListenerCollection listener management
    
    Change-Id: I95961bc77b5f07c9eb57675ce2cada79fec4a2e2
    Reviewed-on: https://gerrit.libreoffice.org/56942
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

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()


More information about the Libreoffice-commits mailing list