Kaydet (Commit) 70d2fd48 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in ImplImageList

and fix leak in RemoveImage in the process

Change-Id: I20e395178f92f7127e99011aebbe97246f255d1d
Reviewed-on: https://gerrit.libreoffice.org/51550Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 58e798c3
......@@ -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())
......
......@@ -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 );
......
......@@ -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;
......
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