Skip to content

Commit

Permalink
Optimize offset_ptr assignment from raw pointer. Previous implementat…
Browse files Browse the repository at this point in the history
…ion used a conversion to offset_ptr leading to redundant operations.
  • Loading branch information
igaztanaga committed Aug 3, 2024
1 parent 6c1db51 commit a53b109
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/boost/interprocess/offset_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,22 @@ class offset_ptr
BOOST_INTERPROCESS_FORCEINLINE reference operator[](difference_type idx) const BOOST_NOEXCEPT
{ return this->get()[idx]; }

//!Assignment from raw pointer. Only takes part in overload resolution if T* is convertible to PointedType*
//!Never throws.

template<class T> BOOST_INTERPROCESS_FORCEINLINE
#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
typename ipcdetail::enable_if_c
< ::boost::move_detail::is_convertible<T*, PointedType*>::value, offset_ptr&>::type
#else
offset_ptr&
#endif
operator= (T *ptr) BOOST_NOEXCEPT
{
this->internal.m_offset = ipcdetail::offset_ptr_to_offset<OffsetType>(static_cast<PointedType*>(ptr), this);
return *this;
}

//!Assignment from other offset_ptr.
//!Never throws.
BOOST_INTERPROCESS_FORCEINLINE offset_ptr& operator= (const offset_ptr & ptr) BOOST_NOEXCEPT
Expand Down

0 comments on commit a53b109

Please sign in to comment.