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

Noel Grandin noel.grandin at collabora.co.uk
Thu Mar 15 10:47:17 UTC 2018


 sc/source/core/data/bcaslot.cxx |   24 +++++++++---------------
 sc/source/core/inc/bcaslot.hxx  |    4 ++--
 2 files changed, 11 insertions(+), 17 deletions(-)

New commits:
commit f725b130e5466a1c4a3a1e070c0eb3548a9a6842
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Mar 15 11:20:14 2018 +0200

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

diff --git a/sc/source/core/data/bcaslot.cxx b/sc/source/core/data/bcaslot.cxx
index 9e1360658e9b..8ee5a1e6587a 100644
--- a/sc/source/core/data/bcaslot.cxx
+++ b/sc/source/core/data/bcaslot.cxx
@@ -659,12 +659,8 @@ ScBroadcastAreaSlotMachine::ScBroadcastAreaSlotMachine(
 
 ScBroadcastAreaSlotMachine::~ScBroadcastAreaSlotMachine()
 {
-    for (TableSlotsMap::iterator iTab( aTableSlotsMap.begin());
-            iTab != aTableSlotsMap.end(); ++iTab)
-    {
-        delete (*iTab).second;
-    }
-    delete pBCAlways;
+    aTableSlotsMap.clear();
+    pBCAlways.reset();
     // Areas to-be-erased still present is a serious error in handling, but at
     // this stage there's nothing we can do anymore.
     SAL_WARN_IF( !maAreasToBeErased.empty(), "sc.core", "ScBroadcastAreaSlotMachine::dtor: maAreasToBeErased not empty");
@@ -727,7 +723,7 @@ void ScBroadcastAreaSlotMachine::StartListeningArea(
     if ( rRange == BCA_LISTEN_ALWAYS  )
     {
         if ( !pBCAlways )
-            pBCAlways = new SvtBroadcaster;
+            pBCAlways.reset( new SvtBroadcaster );
         pListener->StartListening( *pBCAlways );
     }
     else
@@ -743,7 +739,7 @@ void ScBroadcastAreaSlotMachine::StartListeningArea(
         {
             TableSlotsMap::iterator iTab( aTableSlotsMap.find( nTab));
             if (iTab == aTableSlotsMap.end())
-                iTab = aTableSlotsMap.emplace(nTab, new TableSlots).first;
+                iTab = aTableSlotsMap.emplace(nTab, std::unique_ptr<TableSlots>(new TableSlots)).first;
             ScBroadcastAreaSlot** ppSlots = (*iTab).second->getSlots();
             SCSIZE nStart, nEnd, nRowBreak;
             ComputeAreaPoints( rRange, nStart, nEnd, nRowBreak );
@@ -781,8 +777,7 @@ void ScBroadcastAreaSlotMachine::EndListeningArea(
             pListener->EndListening( *pBCAlways);
             if (!pBCAlways->HasListeners())
             {
-                delete pBCAlways;
-                pBCAlways = nullptr;
+                pBCAlways.reset();
             }
         }
     }
@@ -990,14 +985,13 @@ void ScBroadcastAreaSlotMachine::UpdateBroadcastAreas(
             // Remove sheets, if any, iDel or/and iTab may as well point to end().
             while (iDel != iTab)
             {
-                delete (*iDel).second;
                 aTableSlotsMap.erase( iDel++);
             }
             // shift remaining down
             while (iTab != aTableSlotsMap.end())
             {
                 SCTAB nTab = (*iTab).first + nDz;
-                aTableSlotsMap[nTab] = (*iTab).second;
+                aTableSlotsMap[nTab] = std::move((*iTab).second);
                 aTableSlotsMap.erase( iTab++);
             }
         }
@@ -1014,14 +1008,14 @@ void ScBroadcastAreaSlotMachine::UpdateBroadcastAreas(
                 while (iTab != iStop)
                 {
                     SCTAB nTab = (*iTab).first + nDz;
-                    aTableSlotsMap[nTab] = (*iTab).second;
+                    aTableSlotsMap[nTab] = std::move((*iTab).second);
                     aTableSlotsMap.erase( iTab--);
                 }
                 // Shift the very first, iTab==iStop in this case.
                 if (bStopIsBegin)
                 {
                     SCTAB nTab = (*iTab).first + nDz;
-                    aTableSlotsMap[nTab] = (*iTab).second;
+                    aTableSlotsMap[nTab] = std::move((*iTab).second);
                     aTableSlotsMap.erase( iStop);
                 }
             }
@@ -1056,7 +1050,7 @@ void ScBroadcastAreaSlotMachine::UpdateBroadcastAreas(
         {
             TableSlotsMap::iterator iTab( aTableSlotsMap.find( nTab));
             if (iTab == aTableSlotsMap.end())
-                iTab = aTableSlotsMap.emplace(nTab, new TableSlots).first;
+                iTab = aTableSlotsMap.emplace(nTab, std::unique_ptr<TableSlots>(new TableSlots)).first;
             ScBroadcastAreaSlot** ppSlots = (*iTab).second->getSlots();
             SCSIZE nStart, nEnd, nRowBreak;
             ComputeAreaPoints( aRange, nStart, nEnd, nRowBreak );
diff --git a/sc/source/core/inc/bcaslot.hxx b/sc/source/core/inc/bcaslot.hxx
index 34199c2ec972..2ac91fcb4438 100644
--- a/sc/source/core/inc/bcaslot.hxx
+++ b/sc/source/core/inc/bcaslot.hxx
@@ -281,7 +281,7 @@ private:
         TableSlots& operator=( const TableSlots& ) = delete;
     };
 
-    typedef ::std::map< SCTAB, TableSlots* > TableSlotsMap;
+    typedef ::std::map< SCTAB, std::unique_ptr<TableSlots> > TableSlotsMap;
 
     typedef ::std::vector< ::std::pair< ScBroadcastAreaSlot*, ScBroadcastAreas::iterator > > AreasToBeErased;
 
@@ -290,7 +290,7 @@ private:
     BulkGroupAreasType m_BulkGroupAreas;
     TableSlotsMap         aTableSlotsMap;
     AreasToBeErased       maAreasToBeErased;
-    SvtBroadcaster       *pBCAlways;             // for the RC_ALWAYS special range
+    std::unique_ptr<SvtBroadcaster> pBCAlways;             // for the RC_ALWAYS special range
     ScDocument           *pDoc;
     ScBroadcastArea      *pUpdateChain;
     ScBroadcastArea      *pEOUpdateChain;


More information about the Libreoffice-commits mailing list