[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - sc/inc sc/source

Noel Grandin noel.grandin at collabora.co.uk
Fri Apr 21 14:11:31 UTC 2017


 sc/inc/markarr.hxx              |    7 ++++---
 sc/source/core/data/markarr.cxx |   27 ++++++++++-----------------
 2 files changed, 14 insertions(+), 20 deletions(-)

New commits:
commit e659128b744b88dbc72f142c2d8564a1243b5ad4
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Apr 21 16:10:35 2017 +0200

    new loplugin: useuniqueptr: sc part 1 (only the ScMarkArray part)
    
    Change-Id: I24a837c79aaef2246929bb194635f01b4ddedb0b

diff --git a/sc/inc/markarr.hxx b/sc/inc/markarr.hxx
index 2f2e27984486..f92fa94df60c 100644
--- a/sc/inc/markarr.hxx
+++ b/sc/inc/markarr.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_SC_INC_MARKARR_HXX
 
 #include "address.hxx"
+#include <memory>
 
 #define SC_MARKARRAY_DELTA    4
 
@@ -32,9 +33,9 @@ struct ScMarkEntry
 
 class ScMarkArray
 {
-    SCSIZE          nCount;
-    SCSIZE          nLimit;
-    ScMarkEntry*    pData;
+    SCSIZE                            nCount;
+    SCSIZE                            nLimit;
+    std::unique_ptr<ScMarkEntry[]>    pData;
 
 friend class ScMarkArrayIter;
 friend class ScDocument;                // for FillInfo
diff --git a/sc/source/core/data/markarr.cxx b/sc/source/core/data/markarr.cxx
index 62f087cbab78..6266d5afd970 100644
--- a/sc/source/core/data/markarr.cxx
+++ b/sc/source/core/data/markarr.cxx
@@ -35,16 +35,14 @@ ScMarkArray::ScMarkArray() :
 ScMarkArray::ScMarkArray( ScMarkArray&& rArray ) :
     nCount( rArray.nCount ),
     nLimit( rArray.nLimit ),
-    pData( rArray.pData )
+    pData( rArray.pData.release() )
 {
     rArray.nCount = 0;
     rArray.nLimit = 0;
-    rArray.pData = nullptr;
 }
 
 ScMarkArray::~ScMarkArray()
 {
-    delete[] pData;
 }
 
 void ScMarkArray::Reset( bool bMarked, SCSIZE nNeeded )
@@ -52,12 +50,10 @@ void ScMarkArray::Reset( bool bMarked, SCSIZE nNeeded )
     // always create pData here
     // (or have separate method to ensure pData)
 
-    delete[] pData;
-
     assert(nNeeded);
     nLimit = nNeeded;
     nCount = 1;
-    pData = new ScMarkEntry[nNeeded];
+    pData.reset( new ScMarkEntry[nNeeded] );
     pData[0].nRow = MAXROW;
     pData[0].bMarked = bMarked;
 }
@@ -129,9 +125,8 @@ void ScMarkArray::SetMarkArea( SCROW nStartRow, SCROW nEndRow, bool bMarked )
                     if ( nLimit < nNeeded )
                         nLimit = nNeeded;
                     ScMarkEntry* pNewData = new ScMarkEntry[nLimit];
-                    memcpy( pNewData, pData, nCount*sizeof(ScMarkEntry) );
-                    delete[] pData;
-                    pData = pNewData;
+                    memcpy( pNewData, pData.get(), nCount*sizeof(ScMarkEntry) );
+                    pData.reset( pNewData );
                 }
             }
 
@@ -207,7 +202,7 @@ void ScMarkArray::SetMarkArea( SCROW nStartRow, SCROW nEndRow, bool bMarked )
                 }
                 if ( ni < nj )
                 {   // remove entries
-                    memmove( pData + ni, pData + nj, (nCount - nj) * sizeof(ScMarkEntry) );
+                    memmove( pData.get() + ni, pData.get() + nj, (nCount - nj) * sizeof(ScMarkEntry) );
                     nCount -= nj - ni;
                 }
             }
@@ -217,11 +212,11 @@ void ScMarkArray::SetMarkArea( SCROW nStartRow, SCROW nEndRow, bool bMarked )
                 if ( nInsert <= nCount )
                 {
                     if ( !bSplit )
-                        memmove( pData + nInsert + 1, pData + nInsert,
+                        memmove( pData.get() + nInsert + 1, pData.get() + nInsert,
                             (nCount - nInsert) * sizeof(ScMarkEntry) );
                     else
                     {
-                        memmove( pData + nInsert + 2, pData + nInsert,
+                        memmove( pData.get() + nInsert + 2, pData.get() + nInsert,
                             (nCount - nInsert) * sizeof(ScMarkEntry) );
                         pData[nInsert+1] = pData[nInsert-1];
                         nCount++;
@@ -306,15 +301,13 @@ bool ScMarkArray::HasEqualRowsMarked( const ScMarkArray& rOther ) const
 
 void ScMarkArray::CopyMarksTo( ScMarkArray& rDestMarkArray ) const
 {
-    delete[] rDestMarkArray.pData;
-
     if (pData)
     {
-        rDestMarkArray.pData = new ScMarkEntry[nCount];
-        memcpy( rDestMarkArray.pData, pData, nCount * sizeof(ScMarkEntry) );
+        rDestMarkArray.pData.reset( new ScMarkEntry[nCount] );
+        memcpy( rDestMarkArray.pData.get(), pData.get(), nCount * sizeof(ScMarkEntry) );
     }
     else
-        rDestMarkArray.pData = nullptr;
+        rDestMarkArray.pData.reset();
 
     rDestMarkArray.nCount = rDestMarkArray.nLimit = nCount;
 }


More information about the Libreoffice-commits mailing list