diff options
author | Thomas Arnhold <thomas@arnhold.org> | 2013-04-03 12:01:03 +0200 |
---|---|---|
committer | Thorsten Behrens <tbehrens@suse.com> | 2013-04-03 10:05:53 +0000 |
commit | 0c85109e647ab1d1d8d87891b3bba23d90cd7e65 (patch) | |
tree | 585095ce8f6e10bc5ac7ef08075f7f9651ac8540 /drawinglayer | |
parent | 9ab44f12739c40f82c295cab482dc3fcbb656e0f (diff) |
fdo#62525: use cow_wrapper for ViewInformation2D
Change-Id: Ide3bce3257c9fed7bbda7276dfb55fa179d74fdd
Reviewed-on: https://gerrit.libreoffice.org/3183
Tested-by: Thorsten Behrens <tbehrens@suse.com>
Reviewed-by: Thorsten Behrens <tbehrens@suse.com>
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/inc/drawinglayer/geometry/viewinformation2d.hxx | 6 | ||||
-rw-r--r-- | drawinglayer/source/geometry/viewinformation2d.cxx | 80 |
2 files changed, 20 insertions, 66 deletions
diff --git a/drawinglayer/inc/drawinglayer/geometry/viewinformation2d.hxx b/drawinglayer/inc/drawinglayer/geometry/viewinformation2d.hxx index e3d4f23ddd95..f8e0d6699448 100644 --- a/drawinglayer/inc/drawinglayer/geometry/viewinformation2d.hxx +++ b/drawinglayer/inc/drawinglayer/geometry/viewinformation2d.hxx @@ -29,6 +29,7 @@ #include <com/sun/star/uno/Sequence.h> #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/drawing/XDrawPage.hpp> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -58,9 +59,12 @@ namespace drawinglayer */ class DRAWINGLAYER_DLLPUBLIC ViewInformation2D { + public: + typedef o3tl::cow_wrapper< ImpViewInformation2D, o3tl::ThreadSafeRefCountingPolicy > ImplType; + private: /// pointer to private implementation class - ImpViewInformation2D* mpViewInformation2D; + ImplType mpViewInformation2D; public: /** Constructor: Create a ViewInformation2D diff --git a/drawinglayer/source/geometry/viewinformation2d.cxx b/drawinglayer/source/geometry/viewinformation2d.cxx index 6a0b352fc29c..69b541d6ee7d 100644 --- a/drawinglayer/source/geometry/viewinformation2d.cxx +++ b/drawinglayer/source/geometry/viewinformation2d.cxx @@ -24,6 +24,7 @@ #include <basegfx/tools/canvastools.hxx> #include <com/sun/star/geometry/AffineMatrix2D.hpp> #include <com/sun/star/geometry/RealRectangle2D.hpp> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -42,9 +43,6 @@ namespace drawinglayer // two memory regions for pairs of ViewInformation2D/ImpViewInformation2D friend class ::drawinglayer::geometry::ViewInformation2D; - // the refcounter. 0 means exclusively used - sal_uInt32 mnRefCount; - protected: // the object transformation basegfx::B2DHomMatrix maObjectTransformation; @@ -261,8 +259,7 @@ namespace drawinglayer const uno::Reference< drawing::XDrawPage >& rxDrawPage, double fViewTime, const uno::Sequence< beans::PropertyValue >& rExtendedParameters) - : mnRefCount(0), - maObjectTransformation(rObjectTransformation), + : maObjectTransformation(rObjectTransformation), maViewTransformation(rViewTransformation), maObjectToViewTransformation(), maInverseObjectToViewTransformation(), @@ -278,8 +275,7 @@ namespace drawinglayer } explicit ImpViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters) - : mnRefCount(0), - maObjectTransformation(), + : maObjectTransformation(), maViewTransformation(), maObjectToViewTransformation(), maInverseObjectToViewTransformation(), @@ -295,8 +291,7 @@ namespace drawinglayer } ImpViewInformation2D() - : mnRefCount(0), - maObjectTransformation(), + : maObjectTransformation(), maViewTransformation(), maObjectToViewTransformation(), maInverseObjectToViewTransformation(), @@ -407,21 +402,6 @@ namespace drawinglayer && mfViewTime == rCandidate.mfViewTime && mxExtendedInformation == rCandidate.mxExtendedInformation); } - - static ImpViewInformation2D* get_global_default() - { - static ImpViewInformation2D* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpViewInformation2D(); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; } // end of anonymous namespace } // end of namespace drawinglayer @@ -432,6 +412,12 @@ namespace drawinglayer { namespace geometry { + namespace + { + struct theGlobalDefault : + public rtl::Static< ViewInformation2D::ImplType, theGlobalDefault > {}; + } + ViewInformation2D::ViewInformation2D( const basegfx::B2DHomMatrix& rObjectTransformation, const basegfx::B2DHomMatrix& rViewTransformation, @@ -439,7 +425,7 @@ namespace drawinglayer const uno::Reference< drawing::XDrawPage >& rxDrawPage, double fViewTime, const uno::Sequence< beans::PropertyValue >& rExtendedParameters) - : mpViewInformation2D(new ImpViewInformation2D( + : mpViewInformation2D(ImpViewInformation2D( rObjectTransformation, rViewTransformation, rViewport, @@ -450,74 +436,38 @@ namespace drawinglayer } ViewInformation2D::ViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters) - : mpViewInformation2D(new ImpViewInformation2D(rViewParameters)) + : mpViewInformation2D(ImpViewInformation2D(rViewParameters)) { } ViewInformation2D::ViewInformation2D() - : mpViewInformation2D(ImpViewInformation2D::get_global_default()) + : mpViewInformation2D(theGlobalDefault::get()) { - mpViewInformation2D->mnRefCount++; } ViewInformation2D::ViewInformation2D(const ViewInformation2D& rCandidate) : mpViewInformation2D(rCandidate.mpViewInformation2D) { - ::osl::Mutex m_mutex; - mpViewInformation2D->mnRefCount++; } ViewInformation2D::~ViewInformation2D() { - ::osl::Mutex m_mutex; - - if(mpViewInformation2D->mnRefCount) - { - mpViewInformation2D->mnRefCount--; - } - else - { - delete mpViewInformation2D; - } } bool ViewInformation2D::isDefault() const { - return mpViewInformation2D == ImpViewInformation2D::get_global_default(); + return mpViewInformation2D.same_object(theGlobalDefault::get()); } ViewInformation2D& ViewInformation2D::operator=(const ViewInformation2D& rCandidate) { - ::osl::Mutex m_mutex; - - if(mpViewInformation2D->mnRefCount) - { - mpViewInformation2D->mnRefCount--; - } - else - { - delete mpViewInformation2D; - } - mpViewInformation2D = rCandidate.mpViewInformation2D; - mpViewInformation2D->mnRefCount++; - return *this; } bool ViewInformation2D::operator==(const ViewInformation2D& rCandidate) const { - if(rCandidate.mpViewInformation2D == mpViewInformation2D) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpViewInformation2D == *mpViewInformation2D); + return rCandidate.mpViewInformation2D == mpViewInformation2D; } const basegfx::B2DHomMatrix& ViewInformation2D::getObjectTransformation() const |