From 3deaeb9380d43d35cba82e1427492ca6ad0ea01f Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 13 Aug 2018 14:49:37 +0200 Subject: pass IMapObject around by std::unique_ptr and avoid some unnecessary copying Change-Id: Ieb9b1fe169a7d56197bf1e054e9af5dca7804301 Reviewed-on: https://gerrit.libreoffice.org/59019 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svtools/source/misc/imap.cxx | 4 ++++ svtools/source/uno/unoimap.cxx | 17 ++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'svtools') diff --git a/svtools/source/misc/imap.cxx b/svtools/source/misc/imap.cxx index 5118f52db82d..4e23ef612173 100644 --- a/svtools/source/misc/imap.cxx +++ b/svtools/source/misc/imap.cxx @@ -758,6 +758,10 @@ void ImageMap::InsertIMapObject( const IMapObject& rIMapObject ) } } +void ImageMap::InsertIMapObject( std::unique_ptr pNewObject ) +{ + maList.emplace_back( std::move(pNewObject) ); +} /****************************************************************************** |* diff --git a/svtools/source/uno/unoimap.cxx b/svtools/source/uno/unoimap.cxx index 4c337df681d3..2999b5aff1a3 100644 --- a/svtools/source/uno/unoimap.cxx +++ b/svtools/source/uno/unoimap.cxx @@ -78,7 +78,7 @@ public: UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject ) - IMapObject* createIMapObject() const; + std::unique_ptr createIMapObject() const; rtl::Reference mxEvents; @@ -246,7 +246,7 @@ SvUnoImageMapObject::SvUnoImageMapObject( const IMapObject& rMapObject, const Sv mxEvents = new SvMacroTableEventDescriptor( rMapObject.GetMacroTable(), pSupportedMacroItems ); } -IMapObject* SvUnoImageMapObject::createIMapObject() const +std::unique_ptr SvUnoImageMapObject::createIMapObject() const { const OUString aURL( maURL ); const OUString aAltText( maAltText ); @@ -254,21 +254,21 @@ IMapObject* SvUnoImageMapObject::createIMapObject() const const OUString aTarget( maTarget ); const OUString aName( maName ); - IMapObject* pNewIMapObject; + std::unique_ptr pNewIMapObject; switch( mnType ) { case IMAP_OBJ_RECTANGLE: { const tools::Rectangle aRect( maBoundary.X, maBoundary.Y, maBoundary.X + maBoundary.Width - 1, maBoundary.Y + maBoundary.Height - 1 ); - pNewIMapObject = new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false ); + pNewIMapObject.reset(new IMapRectangleObject( aRect, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); } break; case IMAP_OBJ_CIRCLE: { const Point aCenter( maCenter.X, maCenter.Y ); - pNewIMapObject = new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false ); + pNewIMapObject.reset(new IMapCircleObject( aCenter, mnRadius, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); } break; @@ -285,7 +285,7 @@ IMapObject* SvUnoImageMapObject::createIMapObject() const } aPoly.Optimize( PolyOptimizeFlags::CLOSE ); - pNewIMapObject = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false ); + pNewIMapObject.reset(new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, aName, mbIsActive, false )); } break; } @@ -675,9 +675,8 @@ void SvUnoImageMap::fillImageMap( ImageMap& rMap ) const for (auto const& elem : maObjectList) { - IMapObject* pNewMapObject = elem->createIMapObject(); - rMap.InsertIMapObject( *pNewMapObject ); - delete pNewMapObject; + std::unique_ptr pNewMapObject = elem->createIMapObject(); + rMap.InsertIMapObject( std::move(pNewMapObject) ); } } -- cgit