[Bug libstdc++/87514] std::make_shared could avoid virtual call to _Sp_counted_ptr_inplace::_M_get_deleter()
redi at gcc dot gnu.org
Thu Oct 4 11:47:00 GMT 2018
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> In the __shared_ptr(_Sp_make_shared_tag ...) constructor we know the dynamic
> type of *_M_refcount._M_pi is definitely _Sp_counted_ptr_inplace and so
> could theoretically avoid the dynamic dispatch.
> This would require breaking encapsulation to allow __shared_ptr to access
> the private __shared_count::_M_pi member. Is it worth it?
If we're going to do that, we might as well avoid the _M_get_deleter kluge
entirely. We could just directly access _M_refcount._M_pi->_M_ptr() to get the
pointer out, instead of using the _M_get_deleter override as a backchannel.
More information about the Gcc-bugs