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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Aug 6 06:49:06 UTC 2018


 sc/inc/compressedarray.hxx              |    6 +++---
 sc/source/core/data/compressedarray.cxx |   23 ++++++++++-------------
 2 files changed, 13 insertions(+), 16 deletions(-)

New commits:
commit 63d9e2dd97f18ed70b1fd1e8094ff5f74e63f520
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Aug 3 15:56:40 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Aug 6 08:48:46 2018 +0200

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

diff --git a/sc/inc/compressedarray.hxx b/sc/inc/compressedarray.hxx
index ffcdd65176fd..3a112721adbd 100644
--- a/sc/inc/compressedarray.hxx
+++ b/sc/inc/compressedarray.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_SC_INC_COMPRESSEDARRAY_HXX
 
 #include <cstddef>
+#include <memory>
 
 #include "scdllapi.h"
 
@@ -112,7 +113,7 @@ public:
 protected:
     size_t                      nCount;
     size_t                      nLimit;
-    DataEntry*                  pData;
+    std::unique_ptr<DataEntry[]> pData;
     A                           nMaxAccess;
 };
 
@@ -122,9 +123,8 @@ void ScCompressedArray<A,D>::Reset( const D& rValue )
     // Create a temporary copy in case we got a reference passed that points to
     // a part of the array to be reallocated.
     D aTmpVal( rValue);
-    delete[] pData;
     nCount = nLimit = 1;
-    pData = new DataEntry[1];
+    pData.reset(new DataEntry[1]);
     pData[0].aValue = aTmpVal;
     pData[0].nEnd = nMaxAccess;
 }
diff --git a/sc/source/core/data/compressedarray.cxx b/sc/source/core/data/compressedarray.cxx
index 6e8ca59bf5ac..d07de64f5325 100644
--- a/sc/source/core/data/compressedarray.cxx
+++ b/sc/source/core/data/compressedarray.cxx
@@ -39,7 +39,6 @@ ScCompressedArray<A,D>::ScCompressedArray( A nMaxAccessP, const D& rValue )
 template< typename A, typename D >
 ScCompressedArray<A,D>::~ScCompressedArray()
 {
-    delete[] pData;
 }
 
 template< typename A, typename D >
@@ -48,10 +47,9 @@ void ScCompressedArray<A,D>::Resize( size_t nNewLimit)
     if ((nCount <= nNewLimit && nNewLimit < nLimit) || nLimit < nNewLimit)
     {
         nLimit = nNewLimit;
-        DataEntry* pNewData = new DataEntry[nLimit];
-        memcpy( pNewData, pData, nCount*sizeof(DataEntry));
-        delete[] pData;
-        pData = pNewData;
+        std::unique_ptr<DataEntry[]> pNewData(new DataEntry[nLimit]);
+        memcpy( pNewData.get(), pData.get(), nCount*sizeof(DataEntry));
+        pData = std::move(pNewData);
     }
 }
 
@@ -104,10 +102,9 @@ void ScCompressedArray<A,D>::SetValue( A nStart, A nEnd, const D& rValue )
                 nLimit += nScCompressedArrayDelta;
                 if (nLimit < nNeeded)
                     nLimit = nNeeded;
-                DataEntry* pNewData = new DataEntry[nLimit];
-                memcpy( pNewData, pData, nCount*sizeof(DataEntry));
-                delete[] pData;
-                pData = pNewData;
+                std::unique_ptr<DataEntry[]> pNewData(new DataEntry[nLimit]);
+                memcpy( pNewData.get(), pData.get(), nCount*sizeof(DataEntry));
+                pData = std::move(pNewData);
             }
 
             size_t ni;          // number of leading entries
@@ -180,7 +177,7 @@ void ScCompressedArray<A,D>::SetValue( A nStart, A nEnd, const D& rValue )
                 }
                 if (ni < nj)
                 {   // remove entries
-                    memmove( pData + ni, pData + nj,
+                    memmove( pData.get() + ni, pData.get() + nj,
                             (nCount - nj) * sizeof(DataEntry));
                     nCount -= nj - ni;
                 }
@@ -191,11 +188,11 @@ void ScCompressedArray<A,D>::SetValue( A nStart, A nEnd, const D& rValue )
                 if (nInsert <= nCount)
                 {
                     if (!bSplit)
-                        memmove( pData + nInsert + 1, pData + nInsert,
+                        memmove( pData.get() + nInsert + 1, pData.get() + nInsert,
                                 (nCount - nInsert) * sizeof(DataEntry));
                     else
                     {
-                        memmove( pData + nInsert + 2, pData + nInsert,
+                        memmove( pData.get() + nInsert + 2, pData.get() + nInsert,
                                 (nCount - nInsert) * sizeof(DataEntry));
                         pData[nInsert+1] = pData[nInsert-1];
                         nCount++;
@@ -290,7 +287,7 @@ void ScCompressedArray<A,D>::Remove( A nStart, size_t nAccessCount )
         }
         else
             nRemove = 1;
-        memmove( pData + nIndex, pData + nIndex + nRemove, (nCount - (nIndex +
+        memmove( pData.get() + nIndex, pData.get() + nIndex + nRemove, (nCount - (nIndex +
                         nRemove)) * sizeof(DataEntry));
         nCount -= nRemove;
     }


More information about the Libreoffice-commits mailing list