[Libreoffice-commits] core.git: include/svx svx/inc svx/source

Noel Grandin noel.grandin at collabora.co.uk
Wed Oct 4 06:40:58 UTC 2017


 include/svx/xpoly.hxx          |    2 +-
 svx/inc/xpolyimp.hxx           |    4 ++--
 svx/source/svdraw/svdopath.cxx |   14 +++++++-------
 svx/source/xoutdev/_xpoly.cxx  |   36 ++++++++++--------------------------
 4 files changed, 20 insertions(+), 36 deletions(-)

New commits:
commit 224db728733d1beb4709652ace948ff7d1f40f00
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Oct 3 17:15:46 2017 +0200

    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 at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/xpoly.hxx b/include/svx/xpoly.hxx
index a42f1410f79d..a9d53f57e42e 100644
--- a/include/svx/xpoly.hxx
+++ b/include/svx/xpoly.hxx
@@ -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;
diff --git a/svx/inc/xpolyimp.hxx b/svx/inc/xpolyimp.hxx
index 02c9b08e1bef..335117f4ca84 100644
--- a/svx/inc/xpolyimp.hxx
+++ b/svx/inc/xpolyimp.hxx
@@ -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 );
diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx
index 8b4eb625b127..f6cb2bcf48e7 100644
--- a/svx/source/svdraw/svdopath.cxx
+++ b/svx/source/svdraw/svdopath.cxx
@@ -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));
             }
         }
     }
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


More information about the Libreoffice-commits mailing list