diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-03 15:56:40 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-08-06 08:48:46 +0200 |
commit | 63d9e2dd97f18ed70b1fd1e8094ff5f74e63f520 (patch) | |
tree | 9ba9cc653e2c775e67ff4c140b93a6c28f735ef2 | |
parent | 46780892cd3c49c27fdeb4566b7407602901e98f (diff) |
loplugin:useuniqueptr in ScCompressedArray
Change-Id: I6bc46fc209e648e1262ea62e5c13c70a6342ff0d
Reviewed-on: https://gerrit.libreoffice.org/58570
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sc/inc/compressedarray.hxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/compressedarray.cxx | 23 |
2 files changed, 13 insertions, 16 deletions
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; } |