sc/inc/chartpos.hxx                         |   20 ++--
 sc/source/core/tool/chartpos.cxx            |  133 ++++++++--------------------
 sw/inc/IDocumentListsAccess.hxx             |    1 
 sw/source/core/doc/DocumentListsManager.cxx |   46 +--------
 sw/source/core/inc/DocumentListsManager.hxx |    7 -
 5 files changed, 60 insertions(+), 147 deletions(-)

New commits:
commit 12c953fa25cc6c1e56eff6429f73cac8e870a58e
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Sep 26 13:56:59 2018 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Sep 28 09:04:16 2018 +0200

    loplugin:useuniqueptr in DocumentListsManager
    
    Change-Id: Id179245161d707e27e009b6ebc53d925aae5ce0f
    Reviewed-on: https://gerrit.libreoffice.org/61000
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/IDocumentListsAccess.hxx b/sw/inc/IDocumentListsAccess.hxx
index a6bf287b8ccd..ada66af3b574 100644
--- a/sw/inc/IDocumentListsAccess.hxx
+++ b/sw/inc/IDocumentListsAccess.hxx
@@ -31,7 +31,6 @@ class IDocumentListsAccess
     public:
         virtual SwList* createList( const OUString& rListId,
                                     const OUString& rDefaultListStyleName ) = 
0;
-        virtual void deleteList( const OUString& rListId ) = 0;
         virtual SwList* getListByName( const OUString& rListId ) const = 0;
 
         virtual void createListForListStyle( const OUString& rListStyleName ) 
= 0;
diff --git a/sw/source/core/doc/DocumentListsManager.cxx 
b/sw/source/core/doc/DocumentListsManager.cxx
index 1fedbff2cc45..df335c2d6d9e 100644
--- a/sw/source/core/doc/DocumentListsManager.cxx
+++ b/sw/source/core/doc/DocumentListsManager.cxx
@@ -56,30 +56,19 @@ SwList* DocumentListsManager::createList( const OUString& 
rListId,
     }
 
     SwList* pNewList = new SwList( sListId, *pDefaultNumRuleForNewList, 
m_rDoc.GetNodes() );
-    maLists[sListId] = pNewList;
+    maLists[sListId].reset(pNewList);
 
     return pNewList;
 }
 
-void DocumentListsManager::deleteList( const OUString& sListId )
-{
-    SwList* pList = getListByName( sListId );
-    if ( pList )
-    {
-        maLists.erase( sListId );
-        delete pList;
-    }
-}
-
 SwList* DocumentListsManager::getListByName( const OUString& sListId ) const
 {
     SwList* pList = nullptr;
 
-    std::unordered_map< OUString, SwList* >::const_iterator
-                                            aListIter = maLists.find( sListId 
);
+    auto aListIter = maLists.find( sListId );
     if ( aListIter != maLists.end() )
     {
-        pList = (*aListIter).second;
+        pList = (*aListIter).second.get();
     }
 
     return pList;
@@ -145,28 +134,21 @@ void DocumentListsManager::deleteListForListStyle( const 
OUString& sListStyleNam
     if ( !sListId.isEmpty() )
     {
         maListStyleLists.erase( sListStyleName );
-        deleteList( sListId );
+        maLists.erase( sListId );
     }
 }
 
 void DocumentListsManager::deleteListsByDefaultListStyle( const OUString& 
rListStyleName )
 {
-    std::vector< SwList* > aListsForDeletion;
-    tHashMapForLists::iterator aListIter = maLists.begin();
+    auto aListIter = maLists.begin();
     while ( aListIter != maLists.end() )
     {
-        SwList* pList = (*aListIter).second;
-        if ( pList->GetDefaultListStyleName() == rListStyleName )
+        if ( (*aListIter).second->GetDefaultListStyleName() == rListStyleName )
         {
-            aListsForDeletion.push_back( pList );
+            aListIter = maLists.erase(aListIter);
         }
-        ++aListIter;
-    }
-    while ( !aListsForDeletion.empty() )
-    {
-        SwList* pList = aListsForDeletion.back();
-        aListsForDeletion.pop_back();
-        deleteList( pList->GetListId() );
+        else
+            ++aListIter;
     }
 }
 
@@ -194,16 +176,6 @@ void DocumentListsManager::trackChangeOfListStyleName( 
const OUString& sListStyl
 
 DocumentListsManager::~DocumentListsManager()
 {
-    for ( std::unordered_map< OUString, SwList* >::iterator
-                                           aListIter = maLists.begin();
-        aListIter != maLists.end();
-        ++aListIter )
-    {
-         delete (*aListIter).second;
-    }
-    maLists.clear();
-
-    maListStyleLists.clear();
 }
 
 
diff --git a/sw/source/core/inc/DocumentListsManager.hxx 
b/sw/source/core/inc/DocumentListsManager.hxx
index dc6bdc2a5a88..ab02ab41fe8d 100644
--- a/sw/source/core/inc/DocumentListsManager.hxx
+++ b/sw/source/core/inc/DocumentListsManager.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_SW_SOURCE_CORE_INC_DOCUMENTLISTSMANAGER_HXX
 
 #include <IDocumentListsAccess.hxx>
+#include <memory>
 #include <unordered_map>
 
 class SwList;
@@ -38,7 +39,6 @@ class DocumentListsManager : public IDocumentListsAccess
 
         SwList* createList( const OUString& rListId,
                                     const OUString& rDefaultListStyleName ) 
override;
-        void deleteList( const OUString& rListId ) override;
         SwList* getListByName( const OUString& rListId ) const override;
 
         void createListForListStyle( const OUString& rListStyleName ) override;
@@ -57,11 +57,10 @@ class DocumentListsManager : public IDocumentListsAccess
 
         SwDoc& m_rDoc;
 
-        typedef std::unordered_map<OUString, SwList*> tHashMapForLists;
         // container to hold the lists of the text document
-        tHashMapForLists maLists;
+        std::unordered_map<OUString, std::unique_ptr<SwList>> maLists;
         // relation between list style and its default list
-        tHashMapForLists maListStyleLists;
+        std::unordered_map<OUString, SwList*> maListStyleLists;
 
         const OUString CreateUniqueListId();
         const OUString MakeListIdUnique( const OUString& 
aSuggestedUniqueListId );
commit b1f9aa5f58ea322097998839e00d95fc40be8b22
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Wed Sep 26 11:18:06 2018 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Sep 28 09:04:07 2018 +0200

    loplugin:useuniqueptr in ScChartPositionMap
    
    Change-Id: I7c3209dff1c09c40d7a3bb57db0f0b26254318f2
    Reviewed-on: https://gerrit.libreoffice.org/60996
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/chartpos.hxx b/sc/inc/chartpos.hxx
index 275c4da1dafd..0069b1a80c50 100644
--- a/sc/inc/chartpos.hxx
+++ b/sc/inc/chartpos.hxx
@@ -26,17 +26,17 @@
 #include <map>
 
 // map of row number to ScAddress*
-typedef std::map<sal_uLong, ScAddress*> RowMap;
-// map of column number to RowMap*
-typedef std::map<sal_uLong, RowMap*>    ColumnMap;
+typedef std::map<sal_uLong, std::unique_ptr<ScAddress>> RowMap;
+// map of column number to RowMap
+typedef std::map<sal_uLong, RowMap>    ColumnMap;
 
 class ScChartPositionMap
 {
     friend class ScChartPositioner;
 
-            std::unique_ptr<ScAddress*[]> ppData;
-            std::unique_ptr<ScAddress*[]> ppColHeader;
-            std::unique_ptr<ScAddress*[]> ppRowHeader;
+            std::unique_ptr<std::unique_ptr<ScAddress>[]> ppData;
+            std::unique_ptr<std::unique_ptr<ScAddress>[]> ppColHeader;
+            std::unique_ptr<std::unique_ptr<ScAddress>[]> ppRowHeader;
             sal_uLong           nCount;
             SCCOL               nColCount;
             SCROW               nRowCount;
@@ -65,7 +65,7 @@ public:
             const ScAddress*    GetPosition( sal_uLong nIndex ) const
                                     {
                                         if ( nIndex < nCount )
-                                            return ppData[ nIndex ];
+                                            return ppData[ nIndex ].get();
                                         return nullptr;
                                     }
 
@@ -73,19 +73,19 @@ public:
             const ScAddress*    GetPosition( SCCOL nChartCol, SCROW nChartRow 
) const
                                     {
                                         if ( IsValid( nChartCol, nChartRow ) )
-                                            return ppData[ GetIndex( 
nChartCol, nChartRow ) ];
+                                            return ppData[ GetIndex( 
nChartCol, nChartRow ) ].get();
                                         return nullptr;
                                     }
             const ScAddress*    GetColHeaderPosition( SCCOL nChartCol ) const
                                     {
                                         if ( nChartCol < nColCount )
-                                            return ppColHeader[ nChartCol ];
+                                            return ppColHeader[ nChartCol 
].get();
                                         return nullptr;
                                     }
             const ScAddress*    GetRowHeaderPosition( SCROW nChartRow ) const
                                     {
                                         if ( nChartRow < nRowCount )
-                                            return ppRowHeader[ nChartRow ];
+                                            return ppRowHeader[ nChartRow 
].get();
                                         return nullptr;
                                     }
 };
diff --git a/sc/source/core/tool/chartpos.cxx b/sc/source/core/tool/chartpos.cxx
index 7c463fd5dd17..be4a515db9eb 100644
--- a/sc/source/core/tool/chartpos.cxx
+++ b/sc/source/core/tool/chartpos.cxx
@@ -21,6 +21,7 @@
 #include <document.hxx>
 #include <rechead.hxx>
 #include <osl/diagnose.h>
+#include <o3tl/make_unique.hxx>
 
 #include <memory>
 
@@ -354,7 +355,7 @@ void ScChartPositioner::CreatePositionMap()
     GlueState();
 
     const bool bNoGlue = (eGlue == ScChartGlue::NONE);
-    std::unique_ptr<ColumnMap> pCols( new ColumnMap );
+    ColumnMap aColMap;
     SCROW nNoGlueRow = 0;
     for ( size_t i = 0, nRanges = aRangeListRef->size(); i < nRanges; ++i )
     {
@@ -367,15 +368,7 @@ void ScChartPositioner::CreatePositionMap()
                     static_cast<sal_uLong>(nCol1));
             for ( nCol = nCol1; nCol <= nCol2; ++nCol, ++nInsCol )
             {
-                RowMap* pCol = nullptr;
-                ColumnMap::const_iterator it = pCols->find( nInsCol );
-                if ( it == pCols->end() )
-                {
-                    pCol = new RowMap;
-                    pCols->emplace(nInsCol, pCol);
-                }
-                else
-                    pCol = it->second;
+                RowMap* pCol = &aColMap[nInsCol];
 
                 // in other table a new ColKey already was created,
                 // the rows must be equal to be filled with Dummy
@@ -384,7 +377,7 @@ void ScChartPositioner::CreatePositionMap()
                 {
                     if ( pCol->find( nInsRow ) == pCol->end() )
                     {
-                        pCol->emplace( nInsRow, new ScAddress( nCol, nRow, 
nTab ) );
+                        pCol->emplace( nInsRow, o3tl::make_unique<ScAddress>( 
nCol, nRow, nTab ) );
                     }
                 }
             }
@@ -394,13 +387,13 @@ void ScChartPositioner::CreatePositionMap()
     }
 
     // count of data
-    nColCount = static_cast< SCSIZE >( pCols->size());
-    if ( !pCols->empty() )
+    nColCount = static_cast< SCSIZE >( aColMap.size());
+    if ( !aColMap.empty() )
     {
-        RowMap* pCol = pCols->begin()->second;
+        RowMap& rCol = aColMap.begin()->second;
         if ( bDummyUpperLeft )
-            (*pCol)[ 0 ] = nullptr; // Dummy for labeling
-        nRowCount = static_cast< SCSIZE >( pCol->size());
+            rCol[ 0 ] = nullptr; // Dummy for labeling
+        nRowCount = static_cast< SCSIZE >( rCol.size());
     }
     else
         nRowCount = 0;
@@ -411,27 +404,10 @@ void ScChartPositioner::CreatePositionMap()
 
     if ( nColCount==0 || nRowCount==0 )
     {   // create an entry without data
-        RowMap* pCol;
-        if ( !pCols->empty() )
-            pCol = pCols->begin()->second;
-        else
-        {
-            pCol = new RowMap;
-            (*pCols)[ 0 ] = pCol;
-        }
+        RowMap& rCol = aColMap[0];
         nColCount = 1;
-        if ( !pCol->empty() )
-        {   // cannot be if nColCount==0 || nRowCount==0
-            ScAddress* pPos = pCol->begin()->second;
-            if ( pPos )
-            {
-                sal_uLong nCurrentKey = pCol->begin()->first;
-                delete pPos;
-                (*pCol)[ nCurrentKey ] = nullptr;
-            }
-        }
-        else
-            (*pCol)[ 0 ] = nullptr;
+        assert ( rCol.empty() );
+        rCol[ 0 ] = nullptr;
         nRowCount = 1;
         nColAdd = 0;
         nRowAdd = 0;
@@ -440,26 +416,20 @@ void ScChartPositioner::CreatePositionMap()
     {
         if ( bNoGlue )
         {   // fill gaps with Dummies, first column is master
-            RowMap* pFirstCol = pCols->begin()->second;
-            sal_uLong nCount = pFirstCol->size();
-            RowMap::const_iterator it1 = pFirstCol->begin();
+            RowMap& rFirstCol = aColMap.begin()->second;
+            sal_uLong nCount = rFirstCol.size();
+            RowMap::const_iterator it1 = rFirstCol.begin();
             for ( sal_uLong n = 0; n < nCount; n++, ++it1 )
             {
                 sal_uLong nKey = it1->first;
-                for (ColumnMap::const_iterator it2 = ++pCols->begin(); it2 != 
pCols->end(); ++it2 )
-                    it2->second->emplace( nKey, nullptr ); // no data
+                for (ColumnMap::iterator it2 = ++aColMap.begin(); it2 != 
aColMap.end(); ++it2 )
+                    it2->second.emplace( nKey, nullptr ); // no data
             }
         }
     }
 
     pPositionMap.reset( new ScChartPositionMap( static_cast<SCCOL>(nColCount), 
static_cast<SCROW>(nRowCount),
-        static_cast<SCCOL>(nColAdd), static_cast<SCROW>(nRowAdd), *pCols ) );
-
-    //  cleanup
-    for (ColumnMap::const_iterator it = pCols->begin(); it != pCols->end(); 
++it )
-    {   // Only delete tables, not the ScAddress*!
-        delete it->second;
-    }
+        static_cast<SCCOL>(nColAdd), static_cast<SCROW>(nRowAdd), aColMap ) );
 }
 
 void ScChartPositioner::InvalidateGlue()
@@ -470,45 +440,41 @@ void ScChartPositioner::InvalidateGlue()
 
 ScChartPositionMap::ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
             SCCOL nColAdd, SCROW nRowAdd, ColumnMap& rCols ) :
-        ppData( new ScAddress* [ nChartCols * nChartRows ] ),
-        ppColHeader( new ScAddress* [ nChartCols ] ),
-        ppRowHeader( new ScAddress* [ nChartRows ] ),
+        ppData( new std::unique_ptr<ScAddress> [ nChartCols * nChartRows ] ),
+        ppColHeader( new std::unique_ptr<ScAddress> [ nChartCols ] ),
+        ppRowHeader( new std::unique_ptr<ScAddress> [ nChartRows ] ),
         nCount( static_cast<sal_uLong>(nChartCols) * nChartRows ),
         nColCount( nChartCols ),
         nRowCount( nChartRows )
 {
     OSL_ENSURE( nColCount && nRowCount, "ScChartPositionMap without dimension" 
);
 
-    ColumnMap::const_iterator pColIter = rCols.begin();
-    RowMap* pCol1 = pColIter->second;
-    RowMap::const_iterator pPos1Iter;
+    ColumnMap::iterator pColIter = rCols.begin();
+    RowMap& rCol1 = pColIter->second;
+    RowMap::iterator pPos1Iter;
 
     // row header
-    pPos1Iter = pCol1->begin();
+    pPos1Iter = rCol1.begin();
     if ( nRowAdd )
         ++pPos1Iter;
     if ( nColAdd )
     {   // independent
         SCROW nRow = 0;
-        for ( ; nRow < nRowCount && pPos1Iter != pCol1->end(); nRow++ )
+        for ( ; nRow < nRowCount && pPos1Iter != rCol1.end(); nRow++ )
         {
-            ppRowHeader[ nRow ] = pPos1Iter->second;
+            ppRowHeader[ nRow ] = std::move(pPos1Iter->second);
             ++pPos1Iter;
         }
-        for ( ; nRow < nRowCount; nRow++ )
-            ppRowHeader[ nRow ] = nullptr;
     }
     else
     {   // copy
         SCROW nRow = 0;
-        for ( ; nRow < nRowCount && pPos1Iter != pCol1->end(); nRow++ )
+        for ( ; nRow < nRowCount && pPos1Iter != rCol1.end(); nRow++ )
         {
-            ppRowHeader[ nRow ] = pPos1Iter->second ?
-                new ScAddress( *pPos1Iter->second ) : nullptr;
+            if (pPos1Iter->second)
+                ppRowHeader[ nRow ].reset(new ScAddress( *pPos1Iter->second ));
             ++pPos1Iter;
         }
-        for ( ; nRow < nRowCount; nRow++ )
-            ppRowHeader[ nRow ] = nullptr;
     }
     if ( nColAdd )
     {
@@ -521,56 +487,33 @@ ScChartPositionMap::ScChartPositionMap( SCCOL nChartCols, 
SCROW nChartRows,
     {
         if ( pColIter != rCols.end() )
         {
-            RowMap* pCol2 = pColIter->second;
-            RowMap::const_iterator pPosIter = pCol2->begin();
-            if ( pPosIter != pCol2->end() )
+            RowMap& rCol2 = pColIter->second;
+            RowMap::iterator pPosIter = rCol2.begin();
+            if ( pPosIter != rCol2.end() )
             {
                 if ( nRowAdd )
                 {
-                    ppColHeader[ nCol ] = pPosIter->second; // independent
+                    ppColHeader[ nCol ] = std::move(pPosIter->second); // 
independent
                     ++pPosIter;
                 }
-                else
-                    ppColHeader[ nCol ] = pPosIter->second ?
-                        new ScAddress( *pPosIter->second ) : nullptr;
+                else if ( pPosIter->second )
+                    ppColHeader[ nCol ].reset( new ScAddress( 
*pPosIter->second ) );
             }
 
             SCROW nRow = 0;
-            for ( ; nRow < nRowCount && pPosIter != pCol2->end(); nRow++, 
nIndex++ )
+            for ( ; nRow < nRowCount && pPosIter != rCol2.end(); nRow++, 
nIndex++ )
             {
-                ppData[ nIndex ] = pPosIter->second;
+                ppData[ nIndex ] = std::move(pPosIter->second);
                 ++pPosIter;
             }
-            for ( ; nRow < nRowCount; nRow++, nIndex++ )
-                ppData[ nIndex ] = nullptr;
 
             ++pColIter;
         }
-        else
-        {
-            ppColHeader[ nCol ] = nullptr;
-            for ( SCROW nRow = 0; nRow < nRowCount; nRow++, nIndex++ )
-            {
-                ppData[ nIndex ] = nullptr;
-            }
-        }
     }
 }
 
 ScChartPositionMap::~ScChartPositionMap()
 {
-    for ( sal_uLong nIndex=0; nIndex < nCount; nIndex++ )
-    {
-        delete ppData[nIndex];
-    }
-    for ( SCCOL j=0; j < nColCount; j++ )
-    {
-        delete ppColHeader[j];
-    }
-    for ( SCROW i=0; i < nRowCount; i++ )
-    {
-        delete ppRowHeader[i];
-    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to