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

Noel Grandin noel.grandin at collabora.co.uk
Thu Mar 22 06:36:37 UTC 2018


 sc/inc/column.hxx                |    2 +-
 sc/source/core/data/column.cxx   |   23 ++++++++++-------------
 sc/source/core/data/column2.cxx  |    2 +-
 sc/source/core/data/column3.cxx  |    4 ++--
 sc/source/core/data/dociter.cxx  |    8 ++++----
 sc/source/core/data/document.cxx |    2 +-
 sc/source/core/data/fillinfo.cxx |    2 +-
 7 files changed, 20 insertions(+), 23 deletions(-)

New commits:
commit c0a76a9460a4a7db1575bc87744985150462a334
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Mar 20 09:35:45 2018 +0200

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

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 9957b05225fd..4a93f21ed381 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -141,7 +141,7 @@ class ScColumn
     // Cell values.
     sc::CellStoreType maCells;
 
-    ScAttrArray* pAttrArray;
+    std::unique_ptr<ScAttrArray> pAttrArray;
 
     size_t mnBlkCountFormula;
 
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 2dad0de39037..3a1ab1803de3 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -100,7 +100,6 @@ ScColumn::ScColumn() :
 ScColumn::~ScColumn() COVERITY_NOEXCEPT_FALSE
 {
     FreeAll();
-    delete pAttrArray;
 }
 
 void ScColumn::Init(SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc, bool bEmptyAttrArray)
@@ -108,9 +107,9 @@ void ScColumn::Init(SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc, bool bEmptyA
     nCol = nNewCol;
     nTab = nNewTab;
     if ( bEmptyAttrArray )
-        pAttrArray = new ScAttrArray( nCol, nTab, pDoc, nullptr );
+        pAttrArray.reset(new ScAttrArray( nCol, nTab, pDoc, nullptr ));
     else
-        pAttrArray = new ScAttrArray( nCol, nTab, pDoc, &pDoc->maTabs[nTab]->aDefaultColAttrArray );
+        pAttrArray.reset(new ScAttrArray( nCol, nTab, pDoc, &pDoc->maTabs[nTab]->aDefaultColAttrArray ));
 }
 
 SCROW ScColumn::GetNextUnprotected( SCROW nRow, bool bUp ) const
@@ -384,7 +383,7 @@ const ScPatternAttr* ScColumn::GetMostUsedPattern( SCROW nStartRow, SCROW nEndRo
     const ScPatternAttr* pMaxPattern = nullptr;
     size_t nMaxCount = 0;
 
-    ScAttrIterator aAttrIter( pAttrArray, nStartRow, nEndRow, GetDoc()->GetDefPattern() );
+    ScAttrIterator aAttrIter( pAttrArray.get(), nStartRow, nEndRow, GetDoc()->GetDefPattern() );
     const ScPatternAttr* pPattern;
     SCROW nAttrRow1 = 0, nAttrRow2 = 0;
 
@@ -626,7 +625,7 @@ const ScStyleSheet* ScColumn::GetSelectionStyle( const ScMarkData& rMark, bool&
     SCROW nBottom;
     while (bEqual && aMultiIter.Next( nTop, nBottom ))
     {
-        ScAttrIterator aAttrIter( pAttrArray, nTop, nBottom, pDocument->GetDefPattern() );
+        ScAttrIterator aAttrIter( pAttrArray.get(), nTop, nBottom, pDocument->GetDefPattern() );
         SCROW nRow;
         SCROW nDummy;
         const ScPatternAttr* pPattern;
@@ -652,7 +651,7 @@ const ScStyleSheet* ScColumn::GetAreaStyle( bool& rFound, SCROW nRow1, SCROW nRo
     const ScStyleSheet* pStyle = nullptr;
     const ScStyleSheet* pNewStyle;
 
-    ScAttrIterator aAttrIter( pAttrArray, nRow1, nRow2, GetDoc()->GetDefPattern() );
+    ScAttrIterator aAttrIter( pAttrArray.get(), nRow1, nRow2, GetDoc()->GetDefPattern() );
     SCROW nRow;
     SCROW nDummy;
     const ScPatternAttr* pPattern;
@@ -1765,7 +1764,7 @@ void ScColumn::CopyScenarioFrom( const ScColumn& rSrcCol )
 {
     //  This is the scenario table, the data is copied into it
     ScDocument* pDocument = GetDoc();
-    ScAttrIterator aAttrIter( pAttrArray, 0, MAXROW, pDocument->GetDefPattern() );
+    ScAttrIterator aAttrIter( pAttrArray.get(), 0, MAXROW, pDocument->GetDefPattern() );
     SCROW nStart = -1, nEnd = -1;
     const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd );
     while (pPattern)
@@ -1794,7 +1793,7 @@ void ScColumn::CopyScenarioTo( ScColumn& rDestCol ) const
 {
     //  This is the scenario table, the data is copied to the other
     ScDocument* pDocument = GetDoc();
-    ScAttrIterator aAttrIter( pAttrArray, 0, MAXROW, pDocument->GetDefPattern() );
+    ScAttrIterator aAttrIter( pAttrArray.get(), 0, MAXROW, pDocument->GetDefPattern() );
     SCROW nStart = -1, nEnd = -1;
     const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd );
     while (pPattern)
@@ -1819,7 +1818,7 @@ void ScColumn::CopyScenarioTo( ScColumn& rDestCol ) const
 bool ScColumn::TestCopyScenarioTo( const ScColumn& rDestCol ) const
 {
     bool bOk = true;
-    ScAttrIterator aAttrIter( pAttrArray, 0, MAXROW, GetDoc()->GetDefPattern() );
+    ScAttrIterator aAttrIter( pAttrArray.get(), 0, MAXROW, GetDoc()->GetDefPattern() );
     SCROW nStart = 0, nEnd = 0;
     const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd );
     while (pPattern && bOk)
@@ -1837,7 +1836,7 @@ void ScColumn::MarkScenarioIn( ScMarkData& rDestMark ) const
 {
     ScRange aRange( nCol, 0, nTab );
 
-    ScAttrIterator aAttrIter( pAttrArray, 0, MAXROW, GetDoc()->GetDefPattern() );
+    ScAttrIterator aAttrIter( pAttrArray.get(), 0, MAXROW, GetDoc()->GetDefPattern() );
     SCROW nStart = -1, nEnd = -1;
     const ScPatternAttr* pPattern = aAttrIter.Next( nStart, nEnd );
     while (pPattern)
@@ -1945,9 +1944,7 @@ void ScColumn::SwapCol(ScColumn& rCol)
     UpdateNoteCaptions(0, MAXROW);
     rCol.UpdateNoteCaptions(0, MAXROW);
 
-    ScAttrArray* pTempAttr = rCol.pAttrArray;
-    rCol.pAttrArray = pAttrArray;
-    pAttrArray = pTempAttr;
+    std::swap(pAttrArray, rCol.pAttrArray);
 
     // AttrArray needs to have the right column number
     pAttrArray->SetCol(nCol);
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 78bf67a9c1c8..9e866abbd125 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -786,7 +786,7 @@ void ScColumn::GetOptimalHeight(
 {
     ScDocument* pDocument = GetDoc();
     ScFlatUInt16RowSegments& rHeights = rCxt.getHeightArray();
-    ScAttrIterator aIter( pAttrArray, nStartRow, nEndRow, pDocument->GetDefPattern() );
+    ScAttrIterator aIter( pAttrArray.get(), nStartRow, nEndRow, pDocument->GetDefPattern() );
 
     SCROW nStart = -1;
     SCROW nEnd = -1;
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index d42b4479b5d5..c5d75e70d7b0 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1625,7 +1625,7 @@ void ScColumn::MixData(
 
 ScAttrIterator* ScColumn::CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const
 {
-    return new ScAttrIterator( pAttrArray, nStartRow, nEndRow, GetDoc()->GetDefPattern() );
+    return new ScAttrIterator( pAttrArray.get(), nStartRow, nEndRow, GetDoc()->GetDefPattern() );
 }
 
 namespace {
@@ -2440,7 +2440,7 @@ void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow )
     FormulaToValueHandler aFunc;
     sc::CellStoreType::const_iterator itPos = maCells.begin();
 
-    ScAttrIterator aAttrIter( pAttrArray, nStartRow, nEndRow, GetDoc()->GetDefPattern() );
+    ScAttrIterator aAttrIter( pAttrArray.get(), nStartRow, nEndRow, GetDoc()->GetDefPattern() );
     SCROW nTop = -1;
     SCROW nBottom = -1;
     const ScPatternAttr* pPattern = aAttrIter.Next( nTop, nBottom );
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index 90f240e32a3a..bb4cfe10cbe4 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -204,7 +204,7 @@ bool ScValueIterator::GetThis(double& rValue, FormulaError& rErr)
                 if (bCalcAsShown)
                 {
                     ScAttrArray_IterGetNumberFormat(nNumFormat, pAttrArray,
-                        nAttrEndRow, pCol->pAttrArray, nCurRow, pDoc);
+                        nAttrEndRow, pCol->pAttrArray.get(), nCurRow, pDoc);
                     rValue = pDoc->RoundValueAsShown(rValue, nNumFormat);
                 }
                 return true; // Found it!
@@ -323,7 +323,7 @@ const ScAttrArray* ScDBQueryDataIterator::GetAttrArrayByCol(ScDocument& rDoc, SC
     if (nTab >= rDoc.GetTableCount())
         OSL_FAIL("try to access index out of bounds, FIX IT");
     ScColumn* pCol = &rDoc.maTabs[nTab]->aCol[nCol];
-    return pCol->pAttrArray;
+    return pCol->pAttrArray.get();
 }
 
 bool ScDBQueryDataIterator::IsQueryValid(
@@ -2219,7 +2219,7 @@ bool ScHorizontalValueIterator::GetNext( double& rValue, FormulaError& rErr )
                     {
                         ScColumn* pCol = &pDoc->maTabs[nCurTab]->aCol[nCurCol];
                         ScAttrArray_IterGetNumberFormat( nNumFormat, pAttrArray,
-                                nAttrEndRow, pCol->pAttrArray, nCurRow, pDoc );
+                                nAttrEndRow, pCol->pAttrArray.get(), nCurRow, pDoc );
                         rValue = pDoc->RoundValueAsShown( rValue, nNumFormat );
                     }
                     bFound = true;
@@ -2284,7 +2284,7 @@ void ScHorizontalAttrIterator::InitForNextRow(bool bInitialization)
         SCCOL nPos = i - nStartCol;
         if ( bInitialization || pNextEnd[nPos] < nRow )
         {
-            const ScAttrArray* pArray = pDoc->maTabs[nTab]->aCol[i].pAttrArray;
+            const ScAttrArray* pArray = pDoc->maTabs[nTab]->aCol[i].pAttrArray.get();
             OSL_ENSURE( pArray, "pArray == 0" );
 
             SCSIZE nIndex;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index aa1ef7129532..7f4649e7c9d2 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -5451,7 +5451,7 @@ void ScDocument::ExtendOverlapped( SCCOL& rStartCol, SCROW& rStartRow,
 
             //TODO: pass on ?
 
-            ScAttrArray* pAttrArray = maTabs[nTab]->aCol[nOldCol].pAttrArray;
+            ScAttrArray* pAttrArray = maTabs[nTab]->aCol[nOldCol].pAttrArray.get();
             SCSIZE nIndex;
             if ( pAttrArray->Count() )
                 pAttrArray->Search( nOldRow, nIndex );
diff --git a/sc/source/core/data/fillinfo.cxx b/sc/source/core/data/fillinfo.cxx
index 1e3f2c480abc..b150231460a0 100644
--- a/sc/source/core/data/fillinfo.cxx
+++ b/sc/source/core/data/fillinfo.cxx
@@ -469,7 +469,7 @@ void ScDocument::FillInfo(
 
                 if (nX+1 >= nCol1)                                // Attribute/Blockmark from nX1-1
                 {
-                    ScAttrArray* pThisAttrArr = pThisCol->pAttrArray;       // Attribute
+                    ScAttrArray* pThisAttrArr = pThisCol->pAttrArray.get();       // Attribute
                     nArrRow = 0;
 
                     SCROW nCurRow=nRow1;                  // single rows


More information about the Libreoffice-commits mailing list