diff options
author | Mark Page <aptitude@btconnect.com> | 2016-04-29 08:33:13 +0100 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-05-03 06:31:52 +0000 |
commit | e76d458422b0f0f713cc17bf47ca94c33ac570a7 (patch) | |
tree | 728623c04ad9fca76b2eb6a91b509da640d54454 /vcl | |
parent | fa6efd4511a999618fd3958c1c72811dc0ef83ee (diff) |
Change vGDIObj pointer to unique_ptr to reduce WinMtfOutput complexity
Change-Id: Ia81d3b30a874c2e722f7b836db9fab0be2d6e27b
Reviewed-on: https://gerrit.libreoffice.org/24488
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/filter/wmf/winmtf.cxx | 32 | ||||
-rw-r--r-- | vcl/source/filter/wmf/winmtf.hxx | 2 |
2 files changed, 15 insertions, 19 deletions
diff --git a/vcl/source/filter/wmf/winmtf.cxx b/vcl/source/filter/wmf/winmtf.cxx index 5c22b262ca39..ca8141faa713 100644 --- a/vcl/source/filter/wmf/winmtf.cxx +++ b/vcl/source/filter/wmf/winmtf.cxx @@ -29,6 +29,7 @@ #include <rtl/strbuf.hxx> #include <rtl/tencinfo.h> #include <vcl/virdev.hxx> +#include <o3tl/make_unique.hxx> #if OSL_DEBUG_LEVEL > 1 #define EMFP_DEBUG(x) x @@ -531,19 +532,23 @@ tools::PolyPolygon& WinMtfOutput::ImplMap( tools::PolyPolygon& rPolyPolygon ) void WinMtfOutput::SelectObject( sal_Int32 nIndex ) { - GDIObj* pGDIObj = nullptr; + std::unique_ptr<GDIObj> stock_object; + GDIObj *pGDIObj = nullptr; if ( nIndex & ENHMETA_STOCK_OBJECT ) - pGDIObj = new GDIObj(); + { + stock_object = o3tl::make_unique<GDIObj>(); + pGDIObj = stock_object.get(); + } else { nIndex &= 0xffff; // safety check: don't allow index to be > 65535 if ( (sal_uInt32)nIndex < vGDIObj.size() ) - pGDIObj = vGDIObj[ nIndex ]; + pGDIObj = vGDIObj[ nIndex ].get(); } - if( pGDIObj == nullptr ) + if( !pGDIObj ) return; if ( nIndex & ENHMETA_STOCK_OBJECT ) @@ -616,8 +621,6 @@ void WinMtfOutput::SelectObject( sal_Int32 nIndex ) break; // -Wall many options not handled. } } - if ( nIndex & ENHMETA_STOCK_OBJECT ) - delete pGDIObj; } @@ -648,7 +651,7 @@ void WinMtfOutput::SetTextAlign( sal_uInt32 nAlign ) void WinMtfOutput::ImplResizeObjectArry( sal_uInt32 nNewEntrys ) { - vGDIObj.resize(nNewEntrys, nullptr); + vGDIObj.resize(nNewEntrys); } void WinMtfOutput::ImplDrawClippedPolyPolygon( const tools::PolyPolygon& rPolyPoly ) @@ -702,13 +705,13 @@ void WinMtfOutput::CreateObject( GDIObjectType eType, void* pStyle ) sal_uInt32 nIndex; for ( nIndex = 0; nIndex < vGDIObj.size(); nIndex++ ) { - if ( vGDIObj[ nIndex ] == nullptr ) + if ( !vGDIObj[ nIndex ] ) break; } if ( nIndex == vGDIObj.size() ) ImplResizeObjectArry( vGDIObj.size() + 16 ); - vGDIObj[ nIndex ] = new GDIObj( eType, pStyle ); + vGDIObj[ nIndex ] = o3tl::make_unique<GDIObj>( eType, pStyle ); } void WinMtfOutput::CreateObject( sal_Int32 nIndex, GDIObjectType eType, void* pStyle ) @@ -744,10 +747,7 @@ void WinMtfOutput::CreateObject( sal_Int32 nIndex, GDIObjectType eType, void* pS if ( (sal_uInt32)nIndex >= vGDIObj.size() ) ImplResizeObjectArry( nIndex + 16 ); - if ( vGDIObj[ nIndex ] != nullptr ) - delete vGDIObj[ nIndex ]; - - vGDIObj[ nIndex ] = new GDIObj( eType, pStyle ); + vGDIObj[ nIndex ] = o3tl::make_unique<GDIObj>( eType, pStyle ); } else { @@ -776,8 +776,7 @@ void WinMtfOutput::DeleteObject( sal_Int32 nIndex ) { if ( (sal_uInt32)nIndex < vGDIObj.size() ) { - delete vGDIObj[ nIndex ]; - vGDIObj[ nIndex ] = nullptr; + vGDIObj[ nIndex ].reset(); } } } @@ -883,9 +882,6 @@ WinMtfOutput::~WinMtfOutput() mpGDIMetaFile->SetPrefSize( Size( mnDevWidth, mnDevHeight ) ); else mpGDIMetaFile->SetPrefSize( mrclFrame.GetSize() ); - - for ( size_t i = 0; i < vGDIObj.size(); i++ ) - delete vGDIObj[ i ]; } void WinMtfOutput::UpdateClipRegion() diff --git a/vcl/source/filter/wmf/winmtf.hxx b/vcl/source/filter/wmf/winmtf.hxx index 51aba435b70a..db4aa0155953 100644 --- a/vcl/source/filter/wmf/winmtf.hxx +++ b/vcl/source/filter/wmf/winmtf.hxx @@ -551,7 +551,7 @@ class WinMtfOutput RasterOp meLatestRasterOp; RasterOp meRasterOp; - std::vector< GDIObj* > vGDIObj; + std::vector< std::unique_ptr<GDIObj> > vGDIObj; Point maActPos; |