[Libreoffice-commits] core.git: include/o3tl

Daniel Robertson danlrobertson89 at gmail.com
Wed Aug 19 14:25:54 PDT 2015


 include/o3tl/cow_wrapper.hxx |   26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

New commits:
commit 6038ba92be0a4c821ffa29ed0512905e4b3cd8f8
Author: Daniel Robertson <danlrobertson89 at gmail.com>
Date:   Tue Aug 18 17:08:48 2015 -0400

    o3tl: cow_wrapper add move constructor/assignment
    
    Add a move constructor and move assignment operator for
    o3tl::cow_wrapper. Insubstantial gains for UnsafeRefCountingPolicy, no
    atomic increment needed for ThreadSafeRefCountingPolicy's move-ctor.
    
    Change-Id: Ia2de1ca78b1e0e5a0f30535e752f1dd858fdfef0
    Reviewed-on: https://gerrit.libreoffice.org/17848
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/include/o3tl/cow_wrapper.hxx b/include/o3tl/cow_wrapper.hxx
index b7659c3..3f117a2b 100644
--- a/include/o3tl/cow_wrapper.hxx
+++ b/include/o3tl/cow_wrapper.hxx
@@ -121,7 +121,7 @@ public:
     int queryUnmodified() const;
 
 private:
-    otl::cow_wrapper< cow_wrapper_client_impl > maImpl;
+    o3tl::cow_wrapper< cow_wrapper_client_impl > maImpl;
 };
         </pre>
         and the implementation file would look like this:
@@ -187,8 +187,8 @@ int cow_wrapper_client::queryUnmodified() const
 
         void release()
         {
-            if( !MTPolicy::decrementCount(m_pimpl->m_ref_count) )
-                boost::checked_delete(m_pimpl), m_pimpl=0;
+            if( m_pimpl && !MTPolicy::decrementCount(m_pimpl->m_ref_count) )
+                boost::checked_delete(m_pimpl), m_pimpl = nullptr;
         }
 
     public:
@@ -219,6 +219,14 @@ int cow_wrapper_client::queryUnmodified() const
             MTPolicy::incrementCount( m_pimpl->m_ref_count );
         }
 
+        /** Move-construct and steal rSrc shared resource
+         */
+        explicit cow_wrapper( cow_wrapper&& rSrc ) :
+            m_pimpl( rSrc.m_pimpl )
+        {
+            rSrc.m_pimpl = nullptr;
+        }
+
         ~cow_wrapper() // nothrow, if ~T does not throw
         {
             release();
@@ -236,6 +244,18 @@ int cow_wrapper_client::queryUnmodified() const
             return *this;
         }
 
+        /// stealing rSrc's resource
+        cow_wrapper& operator=( cow_wrapper&& rSrc )
+        {
+            // self-movement guts ourself, see also 17.6.4.9
+            release();
+            m_pimpl = rSrc.m_pimpl;
+
+            rSrc.m_pimpl = nullptr;
+
+            return *this;
+        }
+
         /// unshare with any other cow_wrapper instance
         value_type& make_unique()
         {


More information about the Libreoffice-commits mailing list