Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-06-23 08:59:40


Yuval Ronen wrote:
> Hi,
> I'm new to boost, so this post might seem silly to some of you, and I
> apologize if this is the case.
>
> I have a tiny performance suggestion:
>
> The c'tor
>
> template<class Y>
> shared_ptr(shared_ptr<Y> const & r, detail::dynamic_cast_tag):
> px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
> {
> if(px == 0) // need to allocate new counter -- the cast failed
> {
> pn = detail::shared_count();
> }
> }
>
> should be changed to:
>
> template<class Y>
> shared_ptr(shared_ptr<Y> const & r, detail::dynamic_cast_tag):
> px(dynamic_cast<element_type *>(r.px)), pn(px ? r.pn :
> detail::shared_count())
> {
> }

Good suggestion. Unfortunately Borland 5.5.1 seems to have trouble with the
pn( px? r.pn: detail::shared_count() ) initialization, and the performance
gains aren't worth the #ifdef in this case, IMO.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk