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

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


 sc/source/core/data/table4.cxx    |    9 +--
 sc/source/ui/unoobj/chart2uno.cxx |   92 ++++++++++++++++----------------------
 2 files changed, 43 insertions(+), 58 deletions(-)

New commits:
commit 10f2196266dd3bb0fe6c8da0c5967f80815e9492
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Sep 26 13:41:05 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 27 08:34:38 2018 +0200

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

diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 61a818000980..a565ab8433a0 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -611,7 +611,7 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
         const ScPatternAttr* pSrcPattern = nullptr;
         const ScStyleSheet* pStyleSheet = nullptr;
         SCCOLROW nAtSrc = nISrcStart;
-        ScPatternAttr* pNewPattern = nullptr;
+        std::unique_ptr<ScPatternAttr> pNewPattern;
         bool bGetPattern = true;
         rInner = nIStart;
         while (true)        // #i53728# with "for (;;)" old solaris/x86 compiler mis-optimizes
@@ -620,7 +620,6 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
             {
                 if ( bGetPattern )
                 {
-                    delete pNewPattern;
                     if (bVertical)      // rInner&:=nRow, rOuter&:=nCol
                         pSrcPattern = aCol[nCol].GetPattern(static_cast<SCROW>(nAtSrc));
                     else                // rInner&:=nCol, rOuter&:=nRow
@@ -632,13 +631,13 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
                     if ( rSet.GetItemState(ATTR_MERGE, false) == SfxItemState::SET
                             || rSet.GetItemState(ATTR_MERGE_FLAG, false) == SfxItemState::SET )
                     {
-                        pNewPattern = new ScPatternAttr( *pSrcPattern );
+                        pNewPattern.reset( new ScPatternAttr( *pSrcPattern ));
                         SfxItemSet& rNewSet = pNewPattern->GetItemSet();
                         rNewSet.ClearItem(ATTR_MERGE);
                         rNewSet.ClearItem(ATTR_MERGE_FLAG);
                     }
                     else
-                        pNewPattern = nullptr;
+                        pNewPattern.reset();
                 }
 
                 const ScCondFormatItem& rCondFormatItem = pSrcPattern->GetItem(ATTR_CONDITIONAL);
@@ -728,7 +727,7 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
             if (rInner == nIEnd) break;
             if (bPositive) ++rInner; else --rInner;
         }
-        delete pNewPattern;
+        pNewPattern.reset();
 
         //  Analyse
 
commit 2d34c3c421cf8b43fd6601ca688e882f6d493bfc
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Sep 26 13:15:24 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Sep 27 08:34:26 2018 +0200

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

diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 74d79e7d7e04..79ec21b2596d 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -143,7 +143,7 @@ struct TokenTable
 {
     SCROW mnRowCount;
     SCCOL mnColCount;
-    vector<FormulaToken*> maTokens;
+    vector<std::unique_ptr<FormulaToken>> maTokens;
 
     // noncopyable
     TokenTable(const TokenTable&) = delete;
@@ -163,12 +163,13 @@ struct TokenTable
     }
     void clear()
     {
-        std::for_each(maTokens.begin(), maTokens.end(), std::default_delete<FormulaToken>());
+        for (auto & rToken : maTokens)
+            rToken.reset();
     }
 
-    void push_back( FormulaToken* pToken )
+    void push_back( std::unique_ptr<FormulaToken> pToken )
     {
-        maTokens.push_back( pToken );
+        maTokens.push_back( std::move(pToken) );
         OSL_ENSURE( maTokens.size()<= static_cast<sal_uInt32>( mnColCount*mnRowCount ), "too much tokens" );
     }
 
@@ -197,7 +198,7 @@ vector<ScTokenRef> TokenTable::getColRanges(SCCOL nCol) const
     sal_uInt32 nLast = getIndex(nCol, mnRowCount-1);
     for (sal_uInt32 i = getIndex(nCol, 0); i <= nLast; ++i)
     {
-        FormulaToken* p = maTokens[i];
+        FormulaToken* p = maTokens[i].get();
         if (!p)
             continue;
 
@@ -218,7 +219,7 @@ vector<ScTokenRef> TokenTable::getRowRanges(SCROW nRow) const
     sal_uInt32 nLast = getIndex(mnColCount-1, nRow);
     for (sal_uInt32 i = getIndex(0, nRow); i <= nLast; i += mnRowCount)
     {
-        FormulaToken* p = maTokens[i];
+        FormulaToken* p = maTokens[i].get();
         if (!p)
             continue;
 
@@ -234,7 +235,7 @@ vector<ScTokenRef> TokenTable::getAllRanges() const
     sal_uInt32 nStop = mnColCount*mnRowCount;
     for (sal_uInt32 i = 0; i < nStop; i++)
     {
-        FormulaToken* p = maTokens[i];
+        FormulaToken* p = maTokens[i].get();
         if (!p)
             continue;
 
@@ -244,8 +245,8 @@ vector<ScTokenRef> TokenTable::getAllRanges() const
     return aTokens;
 }
 
-typedef std::map<SCROW, FormulaToken*> FormulaTokenMap;
-typedef std::map<sal_uInt32, FormulaTokenMap*> FormulaTokenMapMap;
+typedef std::map<SCROW, std::unique_ptr<FormulaToken>> FormulaTokenMap;
+typedef std::map<sal_uInt32, FormulaTokenMap> FormulaTokenMapMap;
 
 class Chart2PositionMap
 {
@@ -305,7 +306,7 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount,  SCROW nAllRowCount,
             bool bFoundValuesInCol = false;
             bool bFoundAnythingInCol = false;
             SCROW nRow = 0;
-            for (auto it2 = rCol.second->begin(); it2 != rCol.second->end(); ++it2, ++nRow)
+            for (auto it2 = rCol.second.begin(); it2 != rCol.second.end(); ++it2, ++nRow)
             {
                 const auto& rCell = *it2;
 
@@ -365,33 +366,33 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount,  SCROW nAllRowCount,
     maRowHeaders.init(nHeaderColCount,mnDataRowCount);
     maData.init(mnDataColCount,mnDataRowCount);
 
-    FormulaTokenMapMap::const_iterator it1 = rCols.begin();
+    FormulaTokenMapMap::iterator it1 = rCols.begin();
     for (SCCOL nCol = 0; nCol < nAllColCount; ++nCol)
     {
         if (it1 != rCols.end())
         {
-            FormulaTokenMap* pCol = it1->second;
-            FormulaTokenMap::const_iterator it2 = pCol->begin();
+            FormulaTokenMap& rCol = it1->second;
+            FormulaTokenMap::iterator it2 = rCol.begin();
             for (SCROW nRow = 0; nRow < nAllRowCount; ++nRow)
             {
-                FormulaToken* pToken = nullptr;
-                if (it2 != pCol->end())
+                std::unique_ptr<FormulaToken> pToken;
+                if (it2 != rCol.end())
                 {
-                    pToken = it2->second;
+                    pToken = std::move(it2->second);
                     ++it2;
                 }
 
                 if( nCol < nHeaderColCount )
                 {
                     if( nRow < nHeaderRowCount )
-                        maLeftUpperCorner.push_back(pToken);
+                        maLeftUpperCorner.push_back(std::move(pToken));
                     else
-                        maRowHeaders.push_back(pToken);
+                        maRowHeaders.push_back(std::move(pToken));
                 }
                 else if( nRow < nHeaderRowCount )
-                    maColHeaders.push_back(pToken);
+                    maColHeaders.push_back(std::move(pToken));
                 else
-                    maData.push_back(pToken);
+                    maData.push_back(std::move(pToken));
             }
             ++it1;
         }
@@ -718,8 +719,7 @@ void Chart2Positioner::createPositionMap()
     glueState();
 
     bool bNoGlue = (meGlue == GLUETYPE_NONE);
-    unique_ptr<FormulaTokenMapMap> pCols(new FormulaTokenMapMap);
-    FormulaTokenMap* pCol = nullptr;
+    FormulaTokenMapMap aCols;
     SCROW nNoGlueRow = 0;
     for (vector<ScTokenRef>::const_iterator itr = mrRefTokens.begin(), itrEnd = mrRefTokens.end();
           itr != itrEnd; ++itr)
@@ -751,14 +751,7 @@ void Chart2Positioner::createPositionMap()
 
             for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol, ++nInsCol)
             {
-                FormulaTokenMapMap::const_iterator it = pCols->find(nInsCol);
-                if (it == pCols->end())
-                {
-                    pCol = new FormulaTokenMap;
-                    (*pCols)[ nInsCol ] = pCol;
-                }
-                else
-                    pCol = it->second;
+                FormulaTokenMap& rCol = aCols[nInsCol];
 
                 auto nInsRow = bNoGlue ? nNoGlueRow : nRow1;
                 for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow, ++nInsRow)
@@ -773,12 +766,12 @@ void Chart2Positioner::createPositionMap()
                     aCellData.SetAbsRow(nRow);
                     aCellData.SetAbsTab(nTab);
 
-                    if (pCol->find(nInsRow) == pCol->end())
+                    if (rCol.find(nInsRow) == rCol.end())
                     {
                         if (bExternal)
-                            (*pCol)[ nInsRow ] = new ScExternalSingleRefToken(nFileId, aTabName, aCellData);
+                            rCol[ nInsRow ].reset(new ScExternalSingleRefToken(nFileId, aTabName, aCellData));
                         else
-                            (*pCol)[ nInsRow ] = new ScSingleRefToken(aCellData);
+                            rCol[ nInsRow ].reset(new ScSingleRefToken(aCellData));
                     }
                 }
             }
@@ -789,30 +782,30 @@ void Chart2Positioner::createPositionMap()
     bool bFillRowHeader = mbRowHeaders;
     bool bFillColumnHeader = mbColHeaders;
 
-    SCSIZE nAllColCount = static_cast<SCSIZE>(pCols->size());
+    SCSIZE nAllColCount = static_cast<SCSIZE>(aCols.size());
     SCSIZE nAllRowCount = 0;
-    if (!pCols->empty())
+    if (!aCols.empty())
     {
-        pCol = pCols->begin()->second;
+        FormulaTokenMap& rCol = aCols.begin()->second;
         if (mbDummyUpperLeft)
-            if (pCol->find(0) == pCol->end())
-                (*pCol)[ 0 ] = nullptr;        // dummy for labeling
-        nAllRowCount = static_cast<SCSIZE>(pCol->size());
+            if (rCol.find(0) == rCol.end())
+                rCol[ 0 ] = nullptr;        // dummy for labeling
+        nAllRowCount = static_cast<SCSIZE>(rCol.size());
     }
 
     if( nAllColCount!=0 && nAllRowCount!=0 )
     {
         if (bNoGlue)
         {
-            FormulaTokenMap* pFirstCol = pCols->begin()->second;
-            for (FormulaTokenMap::const_iterator it1 = pFirstCol->begin(); it1 != pFirstCol->end(); ++it1)
+            FormulaTokenMap& rFirstCol = aCols.begin()->second;
+            for (FormulaTokenMap::iterator it1 = rFirstCol.begin(); it1 != rFirstCol.end(); ++it1)
             {
                 SCROW nKey = it1->first;
-                for (FormulaTokenMapMap::const_iterator it2 = pCols->begin(); it2 != pCols->end(); ++it2)
+                for (FormulaTokenMapMap::iterator it2 = aCols.begin(); it2 != aCols.end(); ++it2)
                 {
-                    pCol = it2->second;
-                    if (pCol->find(nKey) == pCol->end())
-                        (*pCol)[ nKey ] = nullptr;
+                    FormulaTokenMap& rCol = it2->second;
+                    if (rCol.find(nKey) == rCol.end())
+                        rCol[ nKey ] = nullptr;
                 }
             }
         }
@@ -820,14 +813,7 @@ void Chart2Positioner::createPositionMap()
     mpPositionMap.reset(
         new Chart2PositionMap(
             static_cast<SCCOL>(nAllColCount), static_cast<SCROW>(nAllRowCount),
-            bFillRowHeader, bFillColumnHeader, *pCols, mpDoc));
-
-    // Destroy all column instances.
-    for (FormulaTokenMapMap::const_iterator it = pCols->begin(); it != pCols->end(); ++it)
-    {
-        pCol = it->second;
-        delete pCol;
-    }
+            bFillRowHeader, bFillColumnHeader, aCols, mpDoc));
 }
 
 /**


More information about the Libreoffice-commits mailing list