Boost logo

Boost-Commit :

From: fmhess_at_[hidden]
Date: 2008-04-15 20:06:29


Author: fmhess
Date: 2008-04-15 20:06:29 EDT (Tue, 15 Apr 2008)
New Revision: 44448
URL: http://svn.boost.org/trac/boost/changeset/44448

Log:
Avoid needless overhead of wrapping owner's deleter in deleter_wrapper if
shared_from_this has not been called yet, as Peter suggested
earlier.

Text files modified:
   trunk/boost/enable_shared_from_this.hpp | 22 +++++++++++++---------
   1 files changed, 13 insertions(+), 9 deletions(-)

Modified: trunk/boost/enable_shared_from_this.hpp
==============================================================================
--- trunk/boost/enable_shared_from_this.hpp (original)
+++ trunk/boost/enable_shared_from_this.hpp 2008-04-15 20:06:29 EDT (Tue, 15 Apr 2008)
@@ -93,17 +93,21 @@
     template<typename U>
     void _internal_accept_owner(shared_ptr<U> &owner) const
     {
- init_internal_shared_once();
-
         if( !_owned )
         {
- detail::sp_deleter_wrapper * pd = get_deleter<detail::sp_deleter_wrapper>(_internal_shared_this);
- BOOST_ASSERT( pd != 0 );
- pd->set_deleter(owner);
-
- owner.reset( _internal_shared_this, owner.get() );
- _internal_shared_this.reset();
-
+ if( !_internal_shared_this )
+ {
+ T * p = dynamic_cast<T *>(const_cast<enable_shared_from_this*>(this));
+ _internal_weak_this = shared_ptr<T>(owner, p);
+ }else
+ {
+ detail::sp_deleter_wrapper * pd = get_deleter<detail::sp_deleter_wrapper>(_internal_shared_this);
+ BOOST_ASSERT( pd != 0 );
+ pd->set_deleter(owner);
+
+ owner.reset( _internal_shared_this, owner.get() );
+ _internal_shared_this.reset();
+ }
             _owned = true;
         }
     }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk