[Libreoffice-commits] core.git: vcl/source
Mark Page
aptitude at btconnect.com
Tue May 3 06:32:19 UTC 2016
vcl/source/filter/wmf/winmtf.cxx | 32 ++++++++++++++------------------
vcl/source/filter/wmf/winmtf.hxx | 2 +-
2 files changed, 15 insertions(+), 19 deletions(-)
New commits:
commit e76d458422b0f0f713cc17bf47ca94c33ac570a7
Author: Mark Page <aptitude at btconnect.com>
Date: Fri Apr 29 08:33:13 2016 +0100
Change vGDIObj pointer to unique_ptr to reduce WinMtfOutput complexity
Change-Id: Ia81d3b30a874c2e722f7b836db9fab0be2d6e27b
Reviewed-on: https://gerrit.libreoffice.org/24488
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
diff --git a/vcl/source/filter/wmf/winmtf.cxx b/vcl/source/filter/wmf/winmtf.cxx
index 5c22b26..ca8141f 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 51aba43..db4aa01 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;
More information about the Libreoffice-commits
mailing list