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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Sep 27 06:32:12 UTC 2018


 sc/source/core/data/global.cxx   |    4 ----
 sc/source/core/inc/adiasync.hxx  |    4 ++--
 sc/source/core/tool/adiasync.cxx |   22 ++++++++++++----------
 3 files changed, 14 insertions(+), 16 deletions(-)

New commits:
commit d1c74bda372044154b05c1a0863808ae838b1c42
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Sep 26 12:55:27 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 27 08:31:49 2018 +0200

    loplugin:useuniqueptr in ScAddInAsyncs
    
    Change-Id: I18086623378a6ffd9272b2255ea8060d301b6c43
    Reviewed-on: https://gerrit.libreoffice.org/60997
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx
index 8cb867ace6bb..43bcb6c3cdb9 100644
--- a/sc/source/core/data/global.cxx
+++ b/sc/source/core/data/global.cxx
@@ -543,10 +543,6 @@ void ScGlobal::InitTextHeight(const SfxItemPool* pPool)
 void ScGlobal::Clear()
 {
     // Destroy asyncs _before_ ExitExternalFunc!
-    for( ScAddInAsyncs::iterator it = theAddInAsyncTbl.begin(); it != theAddInAsyncTbl.end(); ++it )
-    {
-        delete *it;
-    }
     theAddInAsyncTbl.clear();
     ExitExternalFunc();
     ClearAutoFormat();
diff --git a/sc/source/core/inc/adiasync.hxx b/sc/source/core/inc/adiasync.hxx
index 50e3924479a1..bc0a22ee3315 100644
--- a/sc/source/core/inc/adiasync.hxx
+++ b/sc/source/core/inc/adiasync.hxx
@@ -69,9 +69,9 @@ public:
 
 struct CompareScAddInAsync
 {
-  bool operator()( ScAddInAsync* const& lhs, ScAddInAsync* const& rhs ) const { return (*lhs)<(*rhs); }
+  bool operator()( std::unique_ptr<ScAddInAsync> const& lhs, std::unique_ptr<ScAddInAsync> const& rhs ) const { return (*lhs)<(*rhs); }
 };
-using ScAddInAsyncs = std::set<ScAddInAsync*, CompareScAddInAsync>;
+using ScAddInAsyncs = std::set<std::unique_ptr<ScAddInAsync>, CompareScAddInAsync>;
 
 extern ScAddInAsyncs theAddInAsyncTbl;  // in adiasync.cxx
 
diff --git a/sc/source/core/tool/adiasync.cxx b/sc/source/core/tool/adiasync.cxx
index e7070603c8c2..9a0770b7addb 100644
--- a/sc/source/core/tool/adiasync.cxx
+++ b/sc/source/core/tool/adiasync.cxx
@@ -50,7 +50,7 @@ ScAddInAsync::ScAddInAsync(sal_uLong nHandleP, LegacyFuncData* pFuncData, ScDocu
 {
     pDocs.reset(new ScAddInDocs);
     pDocs->insert( pDoc );
-    theAddInAsyncTbl.insert( this );
+    theAddInAsyncTbl.emplace( this );
 }
 
 ScAddInAsync::~ScAddInAsync()
@@ -65,26 +65,29 @@ ScAddInAsync::~ScAddInAsync()
 ScAddInAsync* ScAddInAsync::Get( sal_uLong nHandleP )
 {
     ScAddInAsync* pRet = nullptr;
-    ScAddInAsyncs::iterator it = std::find_if(
+    auto it = std::find_if(
         theAddInAsyncTbl.begin(), theAddInAsyncTbl.end(),
-        [nHandleP](ScAddInAsync const * el)
+        [nHandleP](std::unique_ptr<ScAddInAsync> const & el)
             { return el->nHandle == nHandleP; });
     if ( it != theAddInAsyncTbl.end() )
-        pRet = *it;
+        pRet = it->get();
     return pRet;
 }
 
 void ScAddInAsync::CallBack( sal_uLong nHandleP, void* pData )
 {
-    ScAddInAsync* p;
-    if ( (p = Get( nHandleP )) == nullptr )
+    auto asyncIt = std::find_if(
+        theAddInAsyncTbl.begin(), theAddInAsyncTbl.end(),
+        [nHandleP](std::unique_ptr<ScAddInAsync> const & el)
+            { return el->nHandle == nHandleP; });
+    if ( asyncIt == theAddInAsyncTbl.end() )
         return;
+    ScAddInAsync* p = asyncIt->get();
 
     if ( !p->HasListeners() )
     {
         // not in dTor because of theAddInAsyncTbl.DeleteAndDestroy in ScGlobal::Clear
-        theAddInAsyncTbl.erase( p );
-        delete p;
+        theAddInAsyncTbl.erase( asyncIt );
         return ;
     }
     switch ( p->meType )
@@ -122,7 +125,7 @@ void ScAddInAsync::RemoveDocument( ScDocument* pDocumentP )
     {
         for( ScAddInAsyncs::reverse_iterator iter1 = theAddInAsyncTbl.rbegin(); iter1 != theAddInAsyncTbl.rend(); ++iter1 )
         {   // backwards because of pointer-movement in array
-            ScAddInAsync* pAsync = *iter1;
+            ScAddInAsync* pAsync = iter1->get();
             ScAddInDocs* p = pAsync->pDocs.get();
             ScAddInDocs::iterator iter2 = p->find( pDocumentP );
             if( iter2 != p->end() )
@@ -131,7 +134,6 @@ void ScAddInAsync::RemoveDocument( ScDocument* pDocumentP )
                 if ( p->empty() )
                 {   // this AddIn is not used anymore
                     theAddInAsyncTbl.erase( --(iter1.base()) );
-                    delete pAsync;
                 }
             }
         }


More information about the Libreoffice-commits mailing list