Kaydet (Commit) 3deaeb93 authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 9467f10d
......@@ -77,6 +77,7 @@ public:
// a new IMap object is inserted at the end of the Map
void InsertIMapObject( const IMapObject& rIMapObject );
void InsertIMapObject( std::unique_ptr<IMapObject> rIMapObject );
// access to the single ImapObjects; the objects may
// not be destroyed from outside
......
......@@ -182,22 +182,22 @@ IMAPOBJ_SETEVENT:
{
tools::Rectangle aRect( aCoords[0], aCoords[1],
aCoords[2], aCoords[3] );
IMapRectangleObject aMapRObj( aRect, aHRef, aAlt, OUString(), aTarget, aName,
!bNoHRef );
std::unique_ptr<IMapRectangleObject> pMapRObj( new IMapRectangleObject(aRect, aHRef, aAlt, OUString(), aTarget, aName,
!bNoHRef ));
if( !aMacroTbl.empty() )
aMapRObj.SetMacroTable( aMacroTbl );
pImageMap->InsertIMapObject( aMapRObj );
pMapRObj->SetMacroTable( aMacroTbl );
pImageMap->InsertIMapObject( std::move(pMapRObj) );
}
break;
case IMAP_OBJ_CIRCLE:
if( aCoords.size() >=3 )
{
Point aPoint( aCoords[0], aCoords[1] );
IMapCircleObject aMapCObj( aPoint, aCoords[2],aHRef, aAlt, OUString(),
aTarget, aName, !bNoHRef );
std::unique_ptr<IMapCircleObject> pMapCObj(new IMapCircleObject(aPoint, aCoords[2],aHRef, aAlt, OUString(),
aTarget, aName, !bNoHRef ));
if( !aMacroTbl.empty() )
aMapCObj.SetMacroTable( aMacroTbl );
pImageMap->InsertIMapObject( aMapCObj );
pMapCObj->SetMacroTable( aMacroTbl );
pImageMap->InsertIMapObject( std::move(pMapCObj) );
}
break;
case IMAP_OBJ_POLYGON:
......@@ -207,11 +207,11 @@ IMAPOBJ_SETEVENT:
tools::Polygon aPoly( nCount );
for( sal_uInt16 i=0; i<nCount; i++ )
aPoly[i] = Point( aCoords[2*i], aCoords[2*i+1] );
IMapPolygonObject aMapPObj( aPoly, aHRef, aAlt, OUString(), aTarget, aName,
!bNoHRef );
std::unique_ptr<IMapPolygonObject> pMapPObj(new IMapPolygonObject( aPoly, aHRef, aAlt, OUString(), aTarget, aName,
!bNoHRef ));
if( !aMacroTbl.empty() )
aMapPObj.SetMacroTable( aMacroTbl );
pImageMap->InsertIMapObject( aMapPObj );
pMapPObj->SetMacroTable( aMacroTbl );
pImageMap->InsertIMapObject( std::move(pMapPObj) );
}
break;
default:
......
......@@ -758,6 +758,10 @@ void ImageMap::InsertIMapObject( const IMapObject& rIMapObject )
}
}
void ImageMap::InsertIMapObject( std::unique_ptr<IMapObject> pNewObject )
{
maList.emplace_back( std::move(pNewObject) );
}
/******************************************************************************
|*
......
......@@ -78,7 +78,7 @@ public:
UNO3_GETIMPLEMENTATION_DECL( SvUnoImageMapObject )
IMapObject* createIMapObject() const;
std::unique_ptr<IMapObject> createIMapObject() const;
rtl::Reference<SvMacroTableEventDescriptor> 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<IMapObject> 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<IMapObject> 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<IMapObject> pNewMapObject = elem->createIMapObject();
rMap.InsertIMapObject( std::move(pNewMapObject) );
}
}
......
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