diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-19 14:18:37 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-20 07:45:28 +0100 |
commit | 70d2fd4823353550a0e7ffd61585ec1a8a51e907 (patch) | |
tree | 5a6974e250da3a421febd3d1370c61df01a7c717 /framework | |
parent | 58e798c366ba2381a0bf6422036bebe9763035a6 (diff) |
loplugin:useuniqueptr in ImplImageList
and fix leak in RemoveImage in the process
Change-Id: I20e395178f92f7127e99011aebbe97246f255d1d
Reviewed-on: https://gerrit.libreoffice.org/51550
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'framework')
-rw-r--r-- | framework/source/uiconfiguration/ImageList.cxx | 6 | ||||
-rw-r--r-- | framework/source/uiconfiguration/ImplImageList.cxx | 8 | ||||
-rw-r--r-- | framework/source/uiconfiguration/image.h | 2 |
3 files changed, 7 insertions, 9 deletions
diff --git a/framework/source/uiconfiguration/ImageList.cxx b/framework/source/uiconfiguration/ImageList.cxx index 575cfd8de6c6..870d8e3e10db 100644 --- a/framework/source/uiconfiguration/ImageList.cxx +++ b/framework/source/uiconfiguration/ImageList.cxx @@ -68,7 +68,7 @@ BitmapEx ImageList::GetAsHorizontalStrip() const // Load any stragglers for (sal_uInt16 nIdx = 0; nIdx < nCount; nIdx++) { - ImageAryData *pData = mpImplData->maImages[ nIdx ]; + ImageAryData *pData = mpImplData->maImages[ nIdx ].get(); if( pData->IsLoadable() ) pData->Load( mpImplData->maPrefix ); } @@ -81,7 +81,7 @@ BitmapEx ImageList::GetAsHorizontalStrip() const { tools::Rectangle aDestRect( Point( nIdx * mpImplData->maImageSize.Width(), 0 ), mpImplData->maImageSize ); - ImageAryData *pData = mpImplData->maImages[ nIdx ]; + ImageAryData *pData = mpImplData->maImages[ nIdx ].get(); aResult.CopyPixel( aDestRect, aSrcRect, &pData->maBitmapEx); } @@ -214,7 +214,7 @@ void ImageList::GetImageNames( std::vector< OUString >& rNames ) const if( mpImplData ) { - for(const ImageAryData* pImage : mpImplData->maImages) + for(auto const & pImage : mpImplData->maImages) { const OUString& rName( pImage->maName ); if( !rName.isEmpty()) diff --git a/framework/source/uiconfiguration/ImplImageList.cxx b/framework/source/uiconfiguration/ImplImageList.cxx index c759acd6fdf4..1c594f16bf89 100644 --- a/framework/source/uiconfiguration/ImplImageList.cxx +++ b/framework/source/uiconfiguration/ImplImageList.cxx @@ -41,7 +41,7 @@ ImplImageList::ImplImageList( const ImplImageList &aSrc ) for (auto const& elem : aSrc.maImages) { ImageAryData* pAryData = new ImageAryData(*elem); - maImages.push_back( pAryData ); + maImages.emplace_back( pAryData ); if( !pAryData->maName.isEmpty() ) maNameHash [ pAryData->maName ] = pAryData; } @@ -49,22 +49,20 @@ ImplImageList::ImplImageList( const ImplImageList &aSrc ) ImplImageList::~ImplImageList() { - for (auto const& elem : maImages) - delete elem; } void ImplImageList::AddImage( const OUString &aName, sal_uInt16 nId, const BitmapEx &aBitmapEx ) { ImageAryData *pImg = new ImageAryData( aName, nId, aBitmapEx ); - maImages.push_back( pImg ); + maImages.emplace_back( pImg ); if( !aName.isEmpty() ) maNameHash [ aName ] = pImg; } void ImplImageList::RemoveImage( sal_uInt16 nPos ) { - ImageAryData *pImg = maImages[ nPos ]; + ImageAryData *pImg = maImages[ nPos ].get(); if( !pImg->maName.isEmpty() ) maNameHash.erase( pImg->maName ); maImages.erase( maImages.begin() + nPos ); diff --git a/framework/source/uiconfiguration/image.h b/framework/source/uiconfiguration/image.h index 1005fc39cdf1..96c952d3dfe3 100644 --- a/framework/source/uiconfiguration/image.h +++ b/framework/source/uiconfiguration/image.h @@ -48,7 +48,7 @@ struct ImplImageList typedef std::unordered_map< OUString, ImageAryData * > ImageAryDataNameHash; - std::vector<ImageAryData *> maImages; + std::vector< std::unique_ptr<ImageAryData> > maImages; ImageAryDataNameHash maNameHash; OUString maPrefix; Size maImageSize; |