[Libreoffice-commits] core.git: sfx2/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Dec 18 14:56:27 UTC 2018
sfx2/source/doc/doctempl.cxx | 28 ++++++++++------------------
1 file changed, 10 insertions(+), 18 deletions(-)
New commits:
commit 90ebcc45d670fd2acbe2826e7f14570b1a25e04c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Dec 18 14:25:11 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Dec 18 15:56:03 2018 +0100
use unique_ptr in SfxDocTemplate_Impl::InsertRegion
Change-Id: I6b94e0eec328e5b94d20fad011f1ce79e0b2fe84
Reviewed-on: https://gerrit.libreoffice.org/65335
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
index ed0e98114d82..af059b36ca1f 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -224,7 +224,7 @@ public:
RegionData_Impl* GetRegion( size_t nIndex ) const;
bool GetTitleFromURL( const OUString& rURL, OUString& aTitle );
- bool InsertRegion( RegionData_Impl *pData, size_t nPos );
+ bool InsertRegion( std::unique_ptr<RegionData_Impl> pData, size_t nPos );
const OUString& GetRootURL() const { return maRootURL; }
const uno::Reference< XDocumentTemplates >& getDocTemplates() { return mxTemplates; }
@@ -1021,14 +1021,7 @@ bool SfxDocumentTemplates::InsertDir
if ( xTemplates->addGroup( rText ) )
{
- RegionData_Impl* pNewRegion = new RegionData_Impl( pImp.get(), rText );
-
- if ( ! pImp->InsertRegion( pNewRegion, nRegion ) )
- {
- delete pNewRegion;
- return false;
- }
- return true;
+ return pImp->InsertRegion( o3tl::make_unique<RegionData_Impl>( pImp.get(), rText ), nRegion );
}
return false;
@@ -1498,12 +1491,11 @@ void SfxDocTemplate_Impl::DeleteRegion( size_t nIndex )
void SfxDocTemplate_Impl::AddRegion( const OUString& rTitle,
Content& rContent )
{
- RegionData_Impl* pRegion;
- pRegion = new RegionData_Impl( this, rTitle );
+ auto pRegion = o3tl::make_unique<RegionData_Impl>( this, rTitle );
+ auto pRegionTmp = pRegion.get();
- if ( ! InsertRegion( pRegion, size_t(-1) ) )
+ if ( ! InsertRegion( std::move(pRegion), size_t(-1) ) )
{
- delete pRegion;
return;
}
@@ -1530,7 +1522,7 @@ void SfxDocTemplate_Impl::AddRegion( const OUString& rTitle,
{
while ( xResultSet->next() )
{
- pRegion->AddEntry( xRow->getString( 1 ), xRow->getString( 2 ), nullptr );
+ pRegionTmp->AddEntry( xRow->getString( 1 ), xRow->getString( 2 ), nullptr );
}
}
catch ( Exception& ) {}
@@ -1622,13 +1614,13 @@ void SfxDocTemplate_Impl::ReInitFromComponent()
}
-bool SfxDocTemplate_Impl::InsertRegion( RegionData_Impl *pNew, size_t nPos )
+bool SfxDocTemplate_Impl::InsertRegion( std::unique_ptr<RegionData_Impl> pNew, size_t nPos )
{
::osl::MutexGuard aGuard( maMutex );
// return false (not inserted) if the entry already exists
for (auto const& pRegion : maRegions)
- if ( pRegion->Compare( pNew ) == 0 )
+ if ( pRegion->Compare( pNew.get() ) == 0 )
return false;
size_t newPos = nPos;
@@ -1639,10 +1631,10 @@ bool SfxDocTemplate_Impl::InsertRegion( RegionData_Impl *pNew, size_t nPos )
{
auto it = maRegions.begin();
std::advance( it, newPos );
- maRegions.emplace( it, pNew );
+ maRegions.emplace( it, std::move(pNew) );
}
else
- maRegions.emplace_back( pNew );
+ maRegions.emplace_back( std::move(pNew) );
return true;
}
More information about the Libreoffice-commits
mailing list