Changeset 44724


Ignore:
Timestamp:
Apr 22, 2008, 7:48:39 PM (10 years ago)
Author:
Daniel Frey
Message:

Reduce enable_shared_from_this overhead

Location:
trunk/boost
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/boost/detail/shared_count.hpp

    r44711 r44724  
    221221    }
    222222
     223#if defined( BOOST_HAS_RVALUE_REFS )
     224
     225    shared_count(shared_count && r): pi_(r.pi_) // nothrow
     226#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
     227        , id_(shared_count_id)
     228#endif
     229    {
     230        r.pi_ = 0;
     231    }
     232
     233#endif
     234
    223235    explicit shared_count(weak_count const & r); // throws bad_weak_ptr when r.use_count() == 0
    224236    shared_count( weak_count const & r, sp_nothrow_tag ); // constructs an empty *this when r.use_count() == 0
  • trunk/boost/enable_shared_from_this.hpp

    r44499 r44724  
    1414//
    1515
    16 #include <boost/weak_ptr.hpp>
     16#include <boost/detail/shared_count.hpp>
    1717#include <boost/shared_ptr.hpp>
    1818#include <boost/assert.hpp>
     
    3333            _internal_shared_this = shared_ptr<T>( p, detail::sp_deleter_wrapper() );
    3434            BOOST_ASSERT(_internal_shared_this.get() == this);
    35             _internal_weak_this = _internal_shared_this;
     35            _internal_weak_count = _internal_shared_this.get_shared_count();
    3636        }
    3737    }
     
    4444    typedef T _internal_element_type; // for bcc 5.5.1
    4545    mutable shared_ptr<_internal_element_type> _internal_shared_this;
    46     mutable weak_ptr<_internal_element_type> _internal_weak_this;
     46    mutable detail::weak_count _internal_weak_count;
    4747    mutable bool _owned;
    4848
     
    7878    {
    7979        init_internal_shared_once();
    80         shared_ptr<T> p(_internal_weak_this);
    81         BOOST_ASSERT(p.get() == this);
    82         return p;
     80        T * p = dynamic_cast<T *>(this);
     81        return shared_ptr<T>( detail::shared_count( _internal_weak_count ), p );
    8382    }
    8483
     
    8685    {
    8786        init_internal_shared_once();
    88         shared_ptr<T const> p(_internal_weak_this);
    89         BOOST_ASSERT(p.get() == this);
    90         return p;
     87        T const * p = dynamic_cast<T const *>(this);
     88        return shared_ptr<T const>( detail::shared_count( _internal_weak_count ), p );
    9189    }
    9290
     
    9896            if( !_internal_shared_this )
    9997            {
    100                 T * p = dynamic_cast<T *>(const_cast<enable_shared_from_this*>(this));
    101                 _internal_weak_this = shared_ptr<T>(owner, p);
     98                _internal_weak_count = owner.get_shared_count();
    10299            }else
    103100            {
  • trunk/boost/shared_ptr.hpp

    r44707 r44724  
    229229    }
    230230
     231    template<class Y>
     232    shared_ptr(detail::shared_count const & c, Y * p): px(p), pn(c) // never throws
     233    {
     234    }
     235
    231236    // aliasing
    232237    template< class Y >
     
    342347    }
    343348
     349    template<class Y>
     350    shared_ptr(detail::shared_count && c, Y * p): px(p), pn( static_cast< detail::shared_count && >( c ) ) // never throws
     351    {
     352    }
     353
    344354    shared_ptr & operator=( shared_ptr && r ) // never throws
    345355    {
     
    466476        std::swap(px, other.px);
    467477        pn.swap(other.pn);
     478    }
     479
     480    detail::shared_count const & get_shared_count() const // never throws
     481    {
     482        return pn;
    468483    }
    469484
Note: See TracChangeset for help on using the changeset viewer.