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

Xisco Fauli anistenis at gmail.com
Thu Jul 14 07:07:10 UTC 2016


 include/svx/xpoly.hxx         |    7 +--
 svx/inc/xpolyimp.hxx          |    3 -
 svx/source/xoutdev/_xpoly.cxx |   74 +++++++++---------------------------------
 3 files changed, 20 insertions(+), 64 deletions(-)

New commits:
commit 09f88760acddc96cb38febd36fd987eefaa04bc0
Author: Xisco Fauli <anistenis at gmail.com>
Date:   Tue Jul 12 21:22:25 2016 +0200

    tdf#62525 vcl: use cow_wrapper for ImpXPolyPolygon
    
    Change-Id: Ida272942d2fdb0a4a7d4906bbbc2423b459591ac
    Reviewed-on: https://gerrit.libreoffice.org/27170
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noelgrandin at gmail.com>

diff --git a/include/svx/xpoly.hxx b/include/svx/xpoly.hxx
index e68d89d..9400ce5 100644
--- a/include/svx/xpoly.hxx
+++ b/include/svx/xpoly.hxx
@@ -119,13 +119,10 @@ class ImpXPolyPolygon;
 class SVX_DLLPUBLIC XPolyPolygon
 {
 protected:
-    ImpXPolyPolygon* pImpXPolyPolygon;
-
-    // check ImpXPolyPolygon-ReferenceCount and decouple if necessary
-    void    CheckReference();
+    o3tl::cow_wrapper< ImpXPolyPolygon > pImpXPolyPolygon;
 
 public:
-                    XPolyPolygon( sal_uInt16 nInitSize = 16, sal_uInt16 nResize = 16 );
+                    XPolyPolygon();
                     XPolyPolygon( const XPolyPolygon& rXPolyPoly );
 
                     ~XPolyPolygon();
diff --git a/svx/inc/xpolyimp.hxx b/svx/inc/xpolyimp.hxx
index bf6acd4..c3a455a 100644
--- a/svx/inc/xpolyimp.hxx
+++ b/svx/inc/xpolyimp.hxx
@@ -55,9 +55,8 @@ class ImpXPolyPolygon
 {
 public:
     XPolygonList aXPolyList;
-    sal_uInt16       nRefCount;
 
-                ImpXPolyPolygon() { nRefCount = 1; }
+                ImpXPolyPolygon() {}
                 ImpXPolyPolygon( const ImpXPolyPolygon& rImpXPolyPoly );
                 ~ImpXPolyPolygon();
 };
diff --git a/svx/source/xoutdev/_xpoly.cxx b/svx/source/xoutdev/_xpoly.cxx
index 3094116..8c3bce5 100644
--- a/svx/source/xoutdev/_xpoly.cxx
+++ b/svx/source/xoutdev/_xpoly.cxx
@@ -849,11 +849,9 @@ XPolygon::XPolygon(const basegfx::B2DPolygon& rPolygon)
 
 // XPolyPolygon
 
-ImpXPolyPolygon::ImpXPolyPolygon( const ImpXPolyPolygon& rImpXPolyPoly ) :
-                     aXPolyList( rImpXPolyPoly.aXPolyList )
+ImpXPolyPolygon::ImpXPolyPolygon( const ImpXPolyPolygon& rImpXPolyPoly )
+    : aXPolyList( rImpXPolyPoly.aXPolyList )
 {
-    nRefCount = 1;
-
     // duplicate elements
     for (XPolygon*& rp : aXPolyList)
         rp = new XPolygon( *rp );
@@ -866,38 +864,33 @@ ImpXPolyPolygon::~ImpXPolyPolygon()
     aXPolyList.clear();
 }
 
-XPolyPolygon::XPolyPolygon( sal_uInt16 /*nInitSize*/, sal_uInt16 /*nResize*/ )
+XPolyPolygon::XPolyPolygon()
+    : pImpXPolyPolygon()
 {
-    pImpXPolyPolygon = new ImpXPolyPolygon();
 }
 
 XPolyPolygon::XPolyPolygon( const XPolyPolygon& rXPolyPoly )
+    : pImpXPolyPolygon( rXPolyPoly.pImpXPolyPolygon )
 {
-    pImpXPolyPolygon = rXPolyPoly.pImpXPolyPolygon;
-    pImpXPolyPolygon->nRefCount++;
 }
 
-XPolyPolygon::~XPolyPolygon()
+XPolyPolygon::XPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon)
+    : pImpXPolyPolygon()
 {
-    if( pImpXPolyPolygon->nRefCount > 1 )
-        pImpXPolyPolygon->nRefCount--;
-    else
-        delete pImpXPolyPolygon;
+    for(sal_uInt32 a(0L); a < rPolyPolygon.count(); a++)
+    {
+        const basegfx::B2DPolygon aCandidate = rPolyPolygon.getB2DPolygon(a);
+        XPolygon aNewPoly(aCandidate);
+        Insert(aNewPoly);
+    }
 }
 
-/// check reference counter and decouple if > 1
-void XPolyPolygon::CheckReference()
+XPolyPolygon::~XPolyPolygon()
 {
-    if( pImpXPolyPolygon->nRefCount > 1 )
-    {
-        pImpXPolyPolygon->nRefCount--;
-        pImpXPolyPolygon = new ImpXPolyPolygon( *pImpXPolyPolygon );
-    }
 }
 
 void XPolyPolygon::Insert( const XPolygon& rXPoly )
 {
-    CheckReference();
     XPolygon* pXPoly = new XPolygon( rXPoly );
     pImpXPolyPolygon->aXPolyList.push_back( pXPoly );
 }
@@ -905,8 +898,6 @@ void XPolyPolygon::Insert( const XPolygon& rXPoly )
 /// insert all XPolygons of a XPolyPolygon
 void XPolyPolygon::Insert( const XPolyPolygon& rXPolyPoly )
 {
-    CheckReference();
-
     for ( size_t i = 0; i < rXPolyPoly.Count(); i++)
     {
         XPolygon* pXPoly = new XPolygon( rXPolyPoly[i] );
@@ -917,7 +908,6 @@ void XPolyPolygon::Insert( const XPolyPolygon& rXPolyPoly )
 
 XPolygon XPolyPolygon::Remove( sal_uInt16 nPos )
 {
-    CheckReference();
     XPolygonList::iterator it = pImpXPolyPolygon->aXPolyList.begin();
     ::std::advance( it, nPos );
     XPolygon* pTmpXPoly = *it;
@@ -934,17 +924,9 @@ const XPolygon& XPolyPolygon::GetObject( sal_uInt16 nPos ) const
 
 void XPolyPolygon::Clear()
 {
-    if ( pImpXPolyPolygon->nRefCount > 1 )
-    {
-        pImpXPolyPolygon->nRefCount--;
-        pImpXPolyPolygon = new ImpXPolyPolygon();
-    }
-    else
-    {
-        for(XPolygon* p : pImpXPolyPolygon->aXPolyList)
-            delete p;
-        pImpXPolyPolygon->aXPolyList.clear();
-    }
+    for(XPolygon* p : pImpXPolyPolygon->aXPolyList)
+        delete p;
+    pImpXPolyPolygon->aXPolyList.clear();
 }
 
 sal_uInt16 XPolyPolygon::Count() const
@@ -968,19 +950,11 @@ Rectangle XPolyPolygon::GetBoundRect() const
 
 XPolygon& XPolyPolygon::operator[]( sal_uInt16 nPos )
 {
-    CheckReference();
     return *( pImpXPolyPolygon->aXPolyList[ nPos ] );
 }
 
 XPolyPolygon& XPolyPolygon::operator=( const XPolyPolygon& rXPolyPoly )
 {
-    rXPolyPoly.pImpXPolyPolygon->nRefCount++;
-
-    if( pImpXPolyPolygon->nRefCount > 1 )
-        pImpXPolyPolygon->nRefCount--;
-    else
-        delete pImpXPolyPolygon;
-
     pImpXPolyPolygon = rXPolyPoly.pImpXPolyPolygon;
     return *this;
 }
@@ -998,8 +972,6 @@ XPolyPolygon& XPolyPolygon::operator=( const XPolyPolygon& rXPolyPoly )
 void XPolyPolygon::Distort(const Rectangle& rRefRect,
                            const XPolygon& rDistortedRect)
 {
-    CheckReference();
-
     for (size_t i = 0; i < Count(); i++)
         pImpXPolyPolygon->aXPolyList[ i ]->Distort(rRefRect, rDistortedRect);
 }
@@ -1017,16 +989,4 @@ basegfx::B2DPolyPolygon XPolyPolygon::getB2DPolyPolygon() const
     return aRetval;
 }
 
-XPolyPolygon::XPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon)
-{
-    pImpXPolyPolygon = new ImpXPolyPolygon();
-
-    for(sal_uInt32 a(0L); a < rPolyPolygon.count(); a++)
-    {
-        basegfx::B2DPolygon aCandidate = rPolyPolygon.getB2DPolygon(a);
-        XPolygon aNewPoly(aCandidate);
-        Insert(aNewPoly);
-    }
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list