Kaydet (Commit) 6038ba92 authored tarafından Daniel Robertson's avatar Daniel Robertson Kaydeden (comit) Thorsten Behrens

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/17848Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 082a7fae
......@@ -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()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment