Kaydet (Commit) 224db728 authored tarafından Noel Grandin's avatar Noel Grandin

simplify memory management in ImpXPolyPolygon

just use a std::vector<XPolygon>

Change-Id: I1adb801faa8341e0759a86fd209a530b8f5c5a1c
Reviewed-on: https://gerrit.libreoffice.org/43086Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst c9d7d201
......@@ -123,7 +123,7 @@ public:
~XPolyPolygon();
void Insert( const XPolygon& rXPoly );
void Insert( XPolygon&& rXPoly );
void Insert( const XPolyPolygon& rXPoly );
void Remove( sal_uInt16 nPos );
const XPolygon& GetObject( sal_uInt16 nPos ) const;
......
......@@ -51,12 +51,12 @@ public:
void Remove( sal_uInt16 nPos, sal_uInt16 nCount );
};
typedef ::std::vector< XPolygon* > XPolygonList;
typedef ::std::vector< XPolygon > XPolygonVector;
class ImpXPolyPolygon
{
public:
XPolygonList aXPolyList;
XPolygonVector aXPolyList;
ImpXPolyPolygon() {}
ImpXPolyPolygon( const ImpXPolyPolygon& rImpXPolyPoly );
......
......@@ -1155,7 +1155,7 @@ basegfx::B2DPolyPolygon ImpPathForDragAndCreate::getSpecialDragPoly(const SdrDra
if (rXP.GetPointCount()<=2) {
XPolygon aXPoly(rXP);
aXPoly[(sal_uInt16)rDrag.GetHdl()->GetPointNum()]=rDrag.GetNow();
aRetval.Insert(aXPoly);
aRetval.Insert(std::move(aXPoly));
return aRetval.getB2DPolyPolygon();
}
// copy certain data locally to use less code and have faster access times
......@@ -1241,11 +1241,11 @@ basegfx::B2DPolyPolygon ImpPathForDragAndCreate::getSpecialDragPoly(const SdrDra
}
}
}
aRetval.Insert(aXPoly);
if (aLine1.GetPointCount()>1) aRetval.Insert(aLine1);
if (aLine2.GetPointCount()>1) aRetval.Insert(aLine2);
if (aLine3.GetPointCount()>1) aRetval.Insert(aLine3);
if (aLine4.GetPointCount()>1) aRetval.Insert(aLine4);
aRetval.Insert(std::move(aXPoly));
if (aLine1.GetPointCount()>1) aRetval.Insert(std::move(aLine1));
if (aLine2.GetPointCount()>1) aRetval.Insert(std::move(aLine2));
if (aLine3.GetPointCount()>1) aRetval.Insert(std::move(aLine3));
if (aLine4.GetPointCount()>1) aRetval.Insert(std::move(aLine4));
}
return aRetval.getB2DPolyPolygon();
......@@ -1462,7 +1462,7 @@ bool ImpPathForDragAndCreate::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
rXPoly[nActPoint]=rXPoly[0];
XPolygon aXP;
aXP[0]=rStat.GetNow();
aPathPolygon.Insert(aXP);
aPathPolygon.Insert(std::move(aXP));
}
}
}
......
......@@ -862,16 +862,10 @@ XPolygon::XPolygon(const basegfx::B2DPolygon& rPolygon)
ImpXPolyPolygon::ImpXPolyPolygon( const ImpXPolyPolygon& rImpXPolyPoly )
: aXPolyList( rImpXPolyPoly.aXPolyList )
{
// duplicate elements
for (XPolygon*& rp : aXPolyList)
rp = new XPolygon( *rp );
}
ImpXPolyPolygon::~ImpXPolyPolygon()
{
for (XPolygon* p : aXPolyList)
delete p;
aXPolyList.clear();
}
XPolyPolygon::XPolyPolygon()
......@@ -895,8 +889,7 @@ XPolyPolygon::XPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon)
for(sal_uInt32 a(0); a < rPolyPolygon.count(); a++)
{
const basegfx::B2DPolygon aCandidate = rPolyPolygon.getB2DPolygon(a);
XPolygon aNewPoly(aCandidate);
Insert(aNewPoly);
Insert(XPolygon(aCandidate));
}
}
......@@ -904,10 +897,9 @@ XPolyPolygon::~XPolyPolygon()
{
}
void XPolyPolygon::Insert( const XPolygon& rXPoly )
void XPolyPolygon::Insert( XPolygon&& rXPoly )
{
XPolygon* pXPoly = new XPolygon( rXPoly );
pImpXPolyPolygon->aXPolyList.push_back( pXPoly );
pImpXPolyPolygon->aXPolyList.emplace_back( std::move(rXPoly) );
}
/// insert all XPolygons of a XPolyPolygon
......@@ -915,30 +907,22 @@ void XPolyPolygon::Insert( const XPolyPolygon& rXPolyPoly )
{
for ( size_t i = 0; i < rXPolyPoly.Count(); i++)
{
XPolygon* pXPoly = new XPolygon( rXPolyPoly[i] );
pImpXPolyPolygon->aXPolyList.push_back( pXPoly );
pImpXPolyPolygon->aXPolyList.emplace_back( rXPolyPoly[i] );
}
}
void XPolyPolygon::Remove( sal_uInt16 nPos )
{
XPolygonList::iterator it = pImpXPolyPolygon->aXPolyList.begin();
::std::advance( it, nPos );
XPolygon* pTmpXPoly = *it;
pImpXPolyPolygon->aXPolyList.erase( it );
delete pTmpXPoly;
pImpXPolyPolygon->aXPolyList.erase( pImpXPolyPolygon->aXPolyList.begin() + nPos );
}
const XPolygon& XPolyPolygon::GetObject( sal_uInt16 nPos ) const
{
return *(pImpXPolyPolygon->aXPolyList[ nPos ]);
return pImpXPolyPolygon->aXPolyList[ nPos ];
}
void XPolyPolygon::Clear()
{
for(XPolygon* p : pImpXPolyPolygon->aXPolyList)
delete p;
pImpXPolyPolygon->aXPolyList.clear();
}
......@@ -954,8 +938,8 @@ tools::Rectangle XPolyPolygon::GetBoundRect() const
for ( size_t n = 0; n < nXPoly; n++ )
{
const XPolygon* pXPoly = pImpXPolyPolygon->aXPolyList[ n ];
aRect.Union( pXPoly->GetBoundRect() );
XPolygon const & rXPoly = pImpXPolyPolygon->aXPolyList[ n ];
aRect.Union( rXPoly.GetBoundRect() );
}
return aRect;
......@@ -963,7 +947,7 @@ tools::Rectangle XPolyPolygon::GetBoundRect() const
XPolygon& XPolyPolygon::operator[]( sal_uInt16 nPos )
{
return *( pImpXPolyPolygon->aXPolyList[ nPos ] );
return pImpXPolyPolygon->aXPolyList[ nPos ];
}
XPolyPolygon& XPolyPolygon::operator=( const XPolyPolygon& rXPolyPoly )
......@@ -992,7 +976,7 @@ void XPolyPolygon::Distort(const tools::Rectangle& rRefRect,
const XPolygon& rDistortedRect)
{
for (size_t i = 0; i < Count(); i++)
pImpXPolyPolygon->aXPolyList[ i ]->Distort(rRefRect, rDistortedRect);
pImpXPolyPolygon->aXPolyList[ i ].Distort(rRefRect, rDistortedRect);
}
basegfx::B2DPolyPolygon XPolyPolygon::getB2DPolyPolygon() const
......
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