diff options
author | Xisco Fauli <anistenis@gmail.com> | 2016-07-12 21:22:25 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-07-14 07:06:44 +0000 |
commit | 09f88760acddc96cb38febd36fd987eefaa04bc0 (patch) | |
tree | d2078ee7de4d3dfa580dd8ae84d87a058965085a | |
parent | 742e632d8acbe5d0a036d748c062a6616acfdf4a (diff) |
tdf#62525 vcl: use cow_wrapper for ImpXPolyPolygon
Change-Id: Ida272942d2fdb0a4a7d4906bbbc2423b459591ac
Reviewed-on: https://gerrit.libreoffice.org/27170
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r-- | include/svx/xpoly.hxx | 7 | ||||
-rw-r--r-- | svx/inc/xpolyimp.hxx | 3 | ||||
-rw-r--r-- | svx/source/xoutdev/_xpoly.cxx | 74 |
3 files changed, 20 insertions, 64 deletions
diff --git a/include/svx/xpoly.hxx b/include/svx/xpoly.hxx index e68d89dd4420..9400ce55c015 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 bf6acd47a047..c3a455a60e4f 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 309411668456..8c3bce5411c1 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: */ |