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

Noel Grandin noel.grandin at collabora.co.uk
Tue Oct 17 07:00:20 UTC 2017


 sc/source/core/inc/addinlis.hxx  |    3 ++-
 sc/source/core/tool/addinlis.cxx |   24 +++++++++---------------
 2 files changed, 11 insertions(+), 16 deletions(-)

New commits:
commit da6de7dacb7001b569718d413a90f4f56bf0dd31
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Oct 16 13:41:09 2017 +0200

    use rtl::Reference in ScAddInListener
    
    instead of manual ref counting
    
    Change-Id: I04bdb5b34921da9ab08a55a95b99ff1635a9cda6
    Reviewed-on: https://gerrit.libreoffice.org/43420
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/core/inc/addinlis.hxx b/sc/source/core/inc/addinlis.hxx
index c86663194767..5c657621eae9 100644
--- a/sc/source/core/inc/addinlis.hxx
+++ b/sc/source/core/inc/addinlis.hxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/sheet/XVolatileResult.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <cppuhelper/implbase.hxx>
+#include <rtl/ref.hxx>
 #include <list>
 
 class ScDocument;
@@ -40,7 +41,7 @@ private:
     css::uno::Any aResult;
     std::unique_ptr<ScAddInDocs> pDocs; // documents where this is used
 
-    static ::std::list<ScAddInListener*> aAllListeners;
+    static ::std::list<rtl::Reference<ScAddInListener>> aAllListeners;
 
     // always allocated via CreateListener
     ScAddInListener( css::uno::Reference<css::sheet::XVolatileResult> const & xVR,
diff --git a/sc/source/core/tool/addinlis.cxx b/sc/source/core/tool/addinlis.cxx
index 41a68c17c6d9..3181956a10eb 100644
--- a/sc/source/core/tool/addinlis.cxx
+++ b/sc/source/core/tool/addinlis.cxx
@@ -30,20 +30,19 @@ using namespace com::sun::star;
 
 SC_SIMPLE_SERVICE_INFO( ScAddInListener, "ScAddInListener", "stardiv.one.sheet.AddInListener" )
 
-::std::list<ScAddInListener*> ScAddInListener::aAllListeners;
+::std::list<rtl::Reference<ScAddInListener>> ScAddInListener::aAllListeners;
 
 ScAddInListener* ScAddInListener::CreateListener(
                         const uno::Reference<sheet::XVolatileResult>& xVR, ScDocument* pDoc )
 {
-    ScAddInListener* pNew = new ScAddInListener( xVR, pDoc );
+    rtl::Reference<ScAddInListener> xNew = new ScAddInListener( xVR, pDoc );
 
-    pNew->acquire(); // for aAllListeners
-    aAllListeners.push_back( pNew );
+    aAllListeners.push_back( xNew );
 
     if ( xVR.is() )
-        xVR->addResultListener( pNew ); // after at least 1 ref exists!
+        xVR->addResultListener( xNew.get() ); // after at least 1 ref exists!
 
-    return pNew;
+    return xNew.get();
 }
 
 ScAddInListener::ScAddInListener( uno::Reference<sheet::XVolatileResult> const & xVR, ScDocument* pDoc ) :
@@ -62,11 +61,11 @@ ScAddInListener* ScAddInListener::Get( const uno::Reference<sheet::XVolatileResu
     ScAddInListener* pLst = nullptr;
     sheet::XVolatileResult* pComp = xVR.get();
 
-    for(::std::list<ScAddInListener*>::iterator iter = aAllListeners.begin(); iter != aAllListeners.end(); ++iter)
+    for(auto iter = aAllListeners.begin(); iter != aAllListeners.end(); ++iter)
     {
         if ( pComp == (*iter)->xVolRes.get() )
         {
-            pLst = *iter;
+            pLst = iter->get();
             break;
         }
     }
@@ -76,7 +75,7 @@ ScAddInListener* ScAddInListener::Get( const uno::Reference<sheet::XVolatileResu
 //TODO: move to some container object?
 void ScAddInListener::RemoveDocument( ScDocument* pDocumentP )
 {
-    ::std::list<ScAddInListener*>::iterator iter = aAllListeners.begin();
+    auto iter = aAllListeners.begin();
     while(iter != aAllListeners.end())
     {
         ScAddInDocs* p = (*iter)->pDocs.get();
@@ -87,12 +86,7 @@ void ScAddInListener::RemoveDocument( ScDocument* pDocumentP )
             if ( p->empty() )
             {
                 if ( (*iter)->xVolRes.is() )
-                    (*iter)->xVolRes->removeResultListener( *iter );
-
-                (*iter)->release(); // Ref for aAllListeners - pLst may be deleted here
-
-                // this AddIn is no longer used
-                // don't delete, just remove the ref for the list
+                    (*iter)->xVolRes->removeResultListener( iter->get() );
 
                 iter = aAllListeners.erase( iter );
                 continue;


More information about the Libreoffice-commits mailing list