[Libreoffice-commits] core.git: sc/inc sc/source
Noel Grandin
noel.grandin at collabora.co.uk
Wed Jun 27 11:52:21 UTC 2018
sc/inc/addincol.hxx | 8 ++---
sc/source/core/tool/addincol.cxx | 57 ++++++++++++++++-----------------------
2 files changed, 28 insertions(+), 37 deletions(-)
New commits:
commit e5c8f2ba40223b67c7205b6f06da3aa344ed0e97
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Jun 26 15:03:32 2018 +0200
loplugin:useuniqueptr in ScUnoAddInCollection
Change-Id: Ic38eab88f68952549af3417c3e85020877c95446
Reviewed-on: https://gerrit.libreoffice.org/56498
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/addincol.hxx b/sc/inc/addincol.hxx
index e22a6c056f9d..46de0b84c7ef 100644
--- a/sc/inc/addincol.hxx
+++ b/sc/inc/addincol.hxx
@@ -135,10 +135,10 @@ class SC_DLLPUBLIC ScUnoAddInCollection
{
private:
long nFuncCount;
- ScUnoAddInFuncData** ppFuncData;
- ScAddInHashMap* pExactHashMap; ///< exact internal name
- ScAddInHashMap* pNameHashMap; ///< internal name upper
- ScAddInHashMap* pLocalHashMap; ///< localized name upper
+ std::unique_ptr<std::unique_ptr<ScUnoAddInFuncData>[]> ppFuncData;
+ std::unique_ptr<ScAddInHashMap> pExactHashMap; ///< exact internal name
+ std::unique_ptr<ScAddInHashMap> pNameHashMap; ///< internal name upper
+ std::unique_ptr<ScAddInHashMap> pLocalHashMap; ///< localized name upper
bool bInitialized;
void Initialize();
diff --git a/sc/source/core/tool/addincol.cxx b/sc/source/core/tool/addincol.cxx
index 62b0a2f96192..d5a27f22d4e3 100644
--- a/sc/source/core/tool/addincol.cxx
+++ b/sc/source/core/tool/addincol.cxx
@@ -231,21 +231,14 @@ ScUnoAddInCollection::ScUnoAddInCollection() :
ScUnoAddInCollection::~ScUnoAddInCollection()
{
- Clear();
}
void ScUnoAddInCollection::Clear()
{
- DELETEZ( pExactHashMap );
- DELETEZ( pNameHashMap );
- DELETEZ( pLocalHashMap );
- if ( ppFuncData )
- {
- for ( long i=0; i<nFuncCount; i++ )
- delete ppFuncData[i];
- delete[] ppFuncData;
- }
- ppFuncData = nullptr;
+ pExactHashMap.reset();
+ pNameHashMap.reset();
+ pLocalHashMap.reset();
+ ppFuncData.reset();
nFuncCount = 0;
bInitialized = false;
@@ -386,22 +379,21 @@ void ScUnoAddInCollection::ReadConfiguration()
nFuncCount = nNewCount+nOld;
if ( nOld )
{
- ScUnoAddInFuncData** ppNew = new ScUnoAddInFuncData*[nFuncCount];
+ std::unique_ptr<std::unique_ptr<ScUnoAddInFuncData>[]> ppNew(new std::unique_ptr<ScUnoAddInFuncData>[nFuncCount]);
for (long i=0; i<nOld; i++)
- ppNew[i] = ppFuncData[i];
- delete[] ppFuncData;
- ppFuncData = ppNew;
+ ppNew[i] = std::move(ppFuncData[i]);
+ ppFuncData = std::move(ppNew);
}
else
- ppFuncData = new ScUnoAddInFuncData*[nFuncCount];
+ ppFuncData.reset( new std::unique_ptr<ScUnoAddInFuncData>[nFuncCount] );
//TODO: adjust bucket count?
if ( !pExactHashMap )
- pExactHashMap = new ScAddInHashMap;
+ pExactHashMap.reset( new ScAddInHashMap );
if ( !pNameHashMap )
- pNameHashMap = new ScAddInHashMap;
+ pNameHashMap.reset( new ScAddInHashMap );
if ( !pLocalHashMap )
- pLocalHashMap = new ScAddInHashMap;
+ pLocalHashMap.reset( new ScAddInHashMap );
//TODO: get the function information in a single call for all functions?
@@ -552,7 +544,7 @@ void ScUnoAddInCollection::ReadConfiguration()
pData->SetCompNames( aCompNames );
- ppFuncData[nFuncPos+nOld] = pData;
+ ppFuncData[nFuncPos+nOld].reset(pData);
pExactHashMap->emplace(
pData->GetOriginalName(),
@@ -610,7 +602,7 @@ bool ScUnoAddInCollection::GetCalcName( const OUString& rExcelName, OUString& rR
for (long i=0; i<nFuncCount; i++)
{
- ScUnoAddInFuncData* pFuncData = ppFuncData[i];
+ ScUnoAddInFuncData* pFuncData = ppFuncData[i].get();
if ( pFuncData )
{
const ::std::vector<ScUnoAddInFuncData::LocalizedName>& rNames = pFuncData->GetCompNames();
@@ -768,22 +760,21 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
nFuncCount = nNewCount+nOld;
if ( nOld )
{
- ScUnoAddInFuncData** ppNew = new ScUnoAddInFuncData*[nFuncCount];
+ std::unique_ptr<std::unique_ptr<ScUnoAddInFuncData>[]> ppNew(new std::unique_ptr<ScUnoAddInFuncData>[nFuncCount]);
for (long i=0; i<nOld; i++)
- ppNew[i] = ppFuncData[i];
- delete[] ppFuncData;
- ppFuncData = ppNew;
+ ppNew[i] = std::move(ppFuncData[i]);
+ ppFuncData = std::move(ppNew);
}
else
- ppFuncData = new ScUnoAddInFuncData*[nFuncCount];
+ ppFuncData.reset(new std::unique_ptr<ScUnoAddInFuncData>[nFuncCount]);
//TODO: adjust bucket count?
if ( !pExactHashMap )
- pExactHashMap = new ScAddInHashMap;
+ pExactHashMap.reset( new ScAddInHashMap );
if ( !pNameHashMap )
- pNameHashMap = new ScAddInHashMap;
+ pNameHashMap.reset( new ScAddInHashMap );
if ( !pLocalHashMap )
- pLocalHashMap = new ScAddInHashMap;
+ pLocalHashMap.reset( new ScAddInHashMap );
const uno::Reference<reflection::XIdlMethod>* pArray = aMethods.getConstArray();
for (long nFuncPos=0; nFuncPos<nNewCount; nFuncPos++)
@@ -932,14 +923,14 @@ void ScUnoAddInCollection::ReadFromAddIn( const uno::Reference<uno::XInterface>&
OSL_ENSURE( nDestPos==nVisibleCount, "wrong count" );
}
- ppFuncData[nFuncPos+nOld] = new ScUnoAddInFuncData(
+ ppFuncData[nFuncPos+nOld].reset( new ScUnoAddInFuncData(
aFuncName, aLocalName, aDescription,
nCategory, sHelpId,
xFunc, aObject,
- nVisibleCount, pVisibleArgs.get(), nCallerPos );
+ nVisibleCount, pVisibleArgs.get(), nCallerPos ) );
const ScUnoAddInFuncData* pData =
- ppFuncData[nFuncPos+nOld];
+ ppFuncData[nFuncPos+nOld].get();
pExactHashMap->emplace(
pData->GetOriginalName(),
pData );
@@ -1181,7 +1172,7 @@ const ScUnoAddInFuncData* ScUnoAddInCollection::GetFuncData( long nIndex )
Initialize();
if (nIndex < nFuncCount)
- return ppFuncData[nIndex];
+ return ppFuncData[nIndex].get();
return nullptr;
}
More information about the Libreoffice-commits
mailing list