diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-03 17:15:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-04 08:40:26 +0200 |
commit | 224db728733d1beb4709652ace948ff7d1f40f00 (patch) | |
tree | 19d0b061f35b9b45078c289be9741ab243b64806 /svx/source/xoutdev/_xpoly.cxx | |
parent | c9d7d201749ebabe4c8a0d7e5051337b83b50ee7 (diff) |
simplify memory management in ImpXPolyPolygon
just use a std::vector<XPolygon>
Change-Id: I1adb801faa8341e0759a86fd209a530b8f5c5a1c
Reviewed-on: https://gerrit.libreoffice.org/43086
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx/source/xoutdev/_xpoly.cxx')
-rw-r--r-- | svx/source/xoutdev/_xpoly.cxx | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/svx/source/xoutdev/_xpoly.cxx b/svx/source/xoutdev/_xpoly.cxx index 57c850e67d6b..52f08a13ca05 100644 --- a/svx/source/xoutdev/_xpoly.cxx +++ b/svx/source/xoutdev/_xpoly.cxx @@ -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 |