[PATCH] fdo#62525: use cow_wrapper for ViewInformation2D

Thomas Arnhold (via Code Review) gerrit at gerrit.libreoffice.org
Wed Apr 3 03:02:01 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3183

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/83/3183/1

fdo#62525: use cow_wrapper for ViewInformation2D

Change-Id: Ide3bce3257c9fed7bbda7276dfb55fa179d74fdd
---
M drawinglayer/inc/drawinglayer/geometry/viewinformation2d.hxx
M drawinglayer/source/geometry/viewinformation2d.cxx
2 files changed, 20 insertions(+), 66 deletions(-)



diff --git a/drawinglayer/inc/drawinglayer/geometry/viewinformation2d.hxx b/drawinglayer/inc/drawinglayer/geometry/viewinformation2d.hxx
index e3d4f23..f8e0d66 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 @@
         */
         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 6a0b352..69b541d 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>
 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -41,9 +42,6 @@
             // ViewInformation2D implementation can change refcount, so we have only
             // 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
@@ -261,8 +259,7 @@
                 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 @@
             }
 
             explicit ImpViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
-            :   mnRefCount(0),
-                maObjectTransformation(),
+            :   maObjectTransformation(),
                 maViewTransformation(),
                 maObjectToViewTransformation(),
                 maInverseObjectToViewTransformation(),
@@ -295,8 +291,7 @@
             }
 
             ImpViewInformation2D()
-            :   mnRefCount(0),
-                maObjectTransformation(),
+            :   maObjectTransformation(),
                 maViewTransformation(),
                 maObjectToViewTransformation(),
                 maInverseObjectToViewTransformation(),
@@ -407,21 +402,6 @@
                     && 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 geometry
     {
+        namespace
+        {
+            struct theGlobalDefault :
+                public rtl::Static< ViewInformation2D::ImplType, theGlobalDefault > {};
+        }
+
         ViewInformation2D::ViewInformation2D(
             const basegfx::B2DHomMatrix& rObjectTransformation,
             const basegfx::B2DHomMatrix& rViewTransformation,
@@ -439,7 +425,7 @@
             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 @@
         }
 
         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

-- 
To view, visit https://gerrit.libreoffice.org/3183
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ide3bce3257c9fed7bbda7276dfb55fa179d74fdd
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Thomas Arnhold <thomas at arnhold.org>



More information about the LibreOffice mailing list