diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-26 14:53:45 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-27 11:37:01 +0200 |
commit | a98030518682042efaf0d3b603366435edb9e633 (patch) | |
tree | a2d065903c67094684ed9ee08b5c4008089dcce5 /sc | |
parent | 4fc072bf18ab4fa7067905d7785a2100f0391d2e (diff) |
loplugin:useuniqueptr in ScConsData
Change-Id: I0f9392d95ec2887ee62d1486f63600693a8b4dca
Reviewed-on: https://gerrit.libreoffice.org/56497
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/consoli.hxx | 12 | ||||
-rw-r--r-- | sc/source/core/tool/consoli.cxx | 66 |
2 files changed, 26 insertions, 52 deletions
diff --git a/sc/inc/consoli.hxx b/sc/inc/consoli.hxx index d16a082ce578..a2023a62a7d0 100644 --- a/sc/inc/consoli.hxx +++ b/sc/inc/consoli.hxx @@ -53,16 +53,16 @@ private: bool bRowByName; SCSIZE nColCount; SCSIZE nRowCount; - bool** ppUsed; - double** ppSum; - double** ppCount; - double** ppSumSqr; - ScReferenceList** ppRefs; + std::unique_ptr<std::unique_ptr<bool[]>[]> ppUsed; + std::unique_ptr<std::unique_ptr<double[]>[]> ppSum; + std::unique_ptr<std::unique_ptr<double[]>[]> ppCount; + std::unique_ptr<std::unique_ptr<double[]>[]> ppSumSqr; + std::unique_ptr<std::unique_ptr<ScReferenceList[]>[]> ppRefs; ::std::vector<OUString> maColHeaders; ::std::vector<OUString> maRowHeaders; ::std::vector<OUString> maTitles; SCSIZE nDataCount; - SCSIZE** ppTitlePos; + std::unique_ptr<std::unique_ptr<SCSIZE[]>[]> ppTitlePos; bool bCornerUsed; OUString aCornerText; // only for bColByName && bRowByName diff --git a/sc/source/core/tool/consoli.cxx b/sc/source/core/tool/consoli.cxx index dc085b19882f..1c76ed39b342 100644 --- a/sc/source/core/tool/consoli.cxx +++ b/sc/source/core/tool/consoli.cxx @@ -61,49 +61,23 @@ ScConsData::ScConsData() : bRowByName(false), nColCount(0), nRowCount(0), - ppUsed(nullptr), - ppSum(nullptr), - ppCount(nullptr), - ppSumSqr(nullptr), - ppRefs(nullptr), nDataCount(0), - ppTitlePos(nullptr), bCornerUsed(false) { } ScConsData::~ScConsData() { - DeleteData(); -} - -#define DELETEARR(ppArray,nCount) \ -{ \ - sal_uLong i; \ - if (ppArray) \ - for(i=0; i<nCount; i++) \ - delete[] ppArray[i]; \ - delete[] ppArray; \ - ppArray = nullptr; \ } void ScConsData::DeleteData() { - if (ppRefs) - { - for (SCSIZE i=0; i<nColCount; i++) - { - delete[] ppRefs[i]; - } - delete[] ppRefs; - ppRefs = nullptr; - } - - DELETEARR( ppCount, nColCount ); - DELETEARR( ppSum, nColCount ); - DELETEARR( ppSumSqr,nColCount ); - DELETEARR( ppUsed, nColCount ); - DELETEARR( ppTitlePos, nRowCount ); + ppRefs.reset(); + ppCount.reset(); + ppSum.reset(); + ppSumSqr.reset(); + ppUsed.reset(); + ppTitlePos.reset(); ::std::vector<OUString>().swap( maColHeaders); ::std::vector<OUString>().swap( maRowHeaders); ::std::vector<OUString>().swap( maTitles); @@ -123,40 +97,40 @@ void ScConsData::InitData() { if (bReference && nColCount && !ppRefs) { - ppRefs = new ScReferenceList*[nColCount]; + ppRefs.reset(new std::unique_ptr<ScReferenceList[]>[nColCount]); for (SCSIZE i=0; i<nColCount; i++) - ppRefs[i] = new ScReferenceList[nRowCount]; + ppRefs[i].reset(new ScReferenceList[nRowCount]); } else if (nColCount && !ppCount) { - ppCount = new double*[nColCount]; - ppSum = new double*[nColCount]; - ppSumSqr = new double*[nColCount]; + ppCount.reset( new std::unique_ptr<double[]>[nColCount] ); + ppSum.reset( new std::unique_ptr<double[]>[nColCount] ); + ppSumSqr.reset( new std::unique_ptr<double[]>[nColCount] ); for (SCSIZE i=0; i<nColCount; i++) { - ppCount[i] = new double[nRowCount]; - ppSum[i] = new double[nRowCount]; - ppSumSqr[i] = new double[nRowCount]; + ppCount[i].reset( new double[nRowCount] ); + ppSum[i].reset( new double[nRowCount] ); + ppSumSqr[i].reset( new double[nRowCount] ); } } if (nColCount && !ppUsed) { - ppUsed = new bool*[nColCount]; + ppUsed.reset( new std::unique_ptr<bool[]>[nColCount] ); for (SCSIZE i=0; i<nColCount; i++) { - ppUsed[i] = new bool[nRowCount]; - memset( ppUsed[i], 0, nRowCount * sizeof(bool) ); + ppUsed[i].reset( new bool[nRowCount] ); + memset( ppUsed[i].get(), 0, nRowCount * sizeof(bool) ); } } if (nRowCount && nDataCount && !ppTitlePos) { - ppTitlePos = new SCSIZE*[nRowCount]; + ppTitlePos.reset( new std::unique_ptr<SCSIZE[]>[nRowCount] ); for (SCSIZE i=0; i<nRowCount; i++) { - ppTitlePos[i] = new SCSIZE[nDataCount]; - memset( ppTitlePos[i], 0, nDataCount * sizeof(SCSIZE) ); //TODO: not necessary ? + ppTitlePos[i].reset( new SCSIZE[nDataCount] ); + memset( ppTitlePos[i].get(), 0, nDataCount * sizeof(SCSIZE) ); //TODO: not necessary ? } } |