Kaydet (Commit) 63d9e2dd authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in ScCompressedArray

Change-Id: I6bc46fc209e648e1262ea62e5c13c70a6342ff0d
Reviewed-on: https://gerrit.libreoffice.org/58570
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 46780892
......@@ -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;
}
......
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment