summaryrefslogtreecommitdiff
path: root/include/o3tl
diff options
context:
space:
mode:
authorDaniel Robertson <danlrobertson89@gmail.com>2015-08-18 17:08:48 -0400
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2015-08-19 21:25:29 +0000
commit6038ba92be0a4c821ffa29ed0512905e4b3cd8f8 (patch)
tree845cd9dff40d3a0d5e0c169681df7b900ad5b539 /include/o3tl
parent082a7faeedb03c790ba5fe03b466b7a45a822c35 (diff)
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@CIB.de> Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'include/o3tl')
-rw-r--r--include/o3tl/cow_wrapper.hxx26
1 files changed, 23 insertions, 3 deletions
diff --git a/include/o3tl/cow_wrapper.hxx b/include/o3tl/cow_wrapper.hxx
index b7659c3a286f..3f117a2b395b 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()
{