Author: Louis Dionne Date: 2020-12-10T16:45:58-05:00 New Revision: 092e8a7ea3652c418400275746c1800d31390008
URL: https://github.com/llvm/llvm-project/commit/092e8a7ea3652c418400275746c1800d31390008 DIFF: https://github.com/llvm/llvm-project/commit/092e8a7ea3652c418400275746c1800d31390008.diff LOG: [libc++] NFCI: Refactor __shared_ptr_emplace This is the first of a series of patches leading up to the implementation of P0674r1, i.e. array support in allocate_shared. I am splitting this up into multiple patches because the overall change is very tricky and I want to isolate potential breakage. Added: Modified: libcxx/include/memory Removed: ################################################################################ diff --git a/libcxx/include/memory b/libcxx/include/memory index 77d7b67112e32..f3b890ad2b3e9 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -3305,57 +3305,47 @@ __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT } template <class _Tp, class _Alloc> -class __shared_ptr_emplace - : public __shared_weak_count +struct __shared_ptr_emplace + : __shared_weak_count { - __compressed_pair<_Alloc, _Tp> __data_; -public: - - _LIBCPP_INLINE_VISIBILITY - __shared_ptr_emplace(_Alloc __a) - : __data_(_VSTD::move(__a), __value_init_tag()) {} + _LIBCPP_HIDE_FROM_ABI + explicit __shared_ptr_emplace(_Alloc __a) + : __data_(_VSTD::move(__a), __value_init_tag()) + { } -#ifndef _LIBCPP_CXX03_LANG template <class ..._Args> - _LIBCPP_INLINE_VISIBILITY - __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) - : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), - _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {} + _LIBCPP_HIDE_FROM_ABI + explicit __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) +#ifndef _LIBCPP_CXX03_LANG + : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a), + _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) #else - template <class ..._Args> - _LIBCPP_INLINE_VISIBILITY - __shared_ptr_emplace(_Alloc __a, _Args&& ...__args) - : __data_(__a, _Tp(_VSTD::forward<_Args>(__args)...)) {} + : __data_(__a, _Tp(_VSTD::forward<_Args>(__args)...)) #endif + { } + + _LIBCPP_HIDE_FROM_ABI + _Tp* __get_elem() _NOEXCEPT { return _VSTD::addressof(__data_.second()); } + + _LIBCPP_HIDE_FROM_ABI + _Alloc& __get_alloc() _NOEXCEPT { return __data_.first(); } private: - virtual void __on_zero_shared() _NOEXCEPT; - virtual void __on_zero_shared_weak() _NOEXCEPT; -public: - _LIBCPP_INLINE_VISIBILITY - _Alloc& __get_alloc() _NOEXCEPT {return __data_.first();} - _LIBCPP_INLINE_VISIBILITY - _Tp* __get_elem() _NOEXCEPT {return _VSTD::addressof(__data_.second());} -}; + virtual void __on_zero_shared() _NOEXCEPT { + __get_elem()->~_Tp(); + } -template <class _Tp, class _Alloc> -void -__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT -{ - __get_elem()->~_Tp(); -} + virtual void __on_zero_shared_weak() _NOEXCEPT { + using _ControlBlockAlloc = typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type; + using _ControlBlockPointer = typename allocator_traits<_ControlBlockAlloc>::pointer; + _ControlBlockAlloc __tmp(__get_alloc()); + __get_alloc().~_Alloc(); + allocator_traits<_ControlBlockAlloc>::deallocate(__tmp, + pointer_traits<_ControlBlockPointer>::pointer_to(*this), 1); + } -template <class _Tp, class _Alloc> -void -__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT -{ - typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al; - typedef allocator_traits<_Al> _ATraits; - typedef pointer_traits<typename _ATraits::pointer> _PTraits; - _Al __a(__get_alloc()); - __get_alloc().~_Alloc(); - __a.deallocate(_PTraits::pointer_to(*this), 1); -} + __compressed_pair<_Alloc, _Tp> __data_; +}; struct __shared_ptr_dummy_rebind_allocator_type; template <> _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits