From: Jonathan Wakely Date: Wed, 4 Jul 2018 13:59:42 +0000 (+0100) Subject: PR libstdc++/86127 avoid unnecessary allocator conversions X-Git-Tag: releases/gcc-7.4.0~278 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=822af00440abd7a5f2f974a062b7425da2e2ca08;p=thirdparty%2Fgcc.git PR libstdc++/86127 avoid unnecessary allocator conversions There is no need to use an allocator of the correct value_type when calling allocator_traits::construct and allocator_traits::destroy. The existing node allocator can be used, instead of constructing a new allocator object every time. There's also no benefit to using __gnu_cxx::__alloc_traits instead of std::allocator_traits to get the pointer and const_pointer types. std::forward_list is only available for C++11 and later, when std::allocator_traits is available too. Backport from mainline 2018-06-13 Jonathan Wakely PR libstdc++/86127 * include/bits/forward_list.h (_Fwd_list_base::_Tp_alloc_type): Remove unused typedef. (_Fwd_list_base::_M_create_node, _Fwd_list_base::_M_erase_after): Use node allocator to create and destroy elements. (forward_list::_Tp_alloc_type): Remove unused typedef. (forward_list::_Alloc_traits): Use allocator_traits instead of __gnu_cxx::__alloc_traits. * include/bits/forward_list.tcc (_Fwd_list_base::_M_erase_after): Use node allocator to create and destroy elements. From-SVN: r262411 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e174d8d24d16..772c62fce406 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,19 @@ 2018-07-04 Jonathan Wakely + Backport from mainline + 2018-06-13 Jonathan Wakely + + PR libstdc++/86127 + * include/bits/forward_list.h (_Fwd_list_base::_Tp_alloc_type): Remove + unused typedef. + (_Fwd_list_base::_M_create_node, _Fwd_list_base::_M_erase_after): + Use node allocator to create and destroy elements. + (forward_list::_Tp_alloc_type): Remove unused typedef. + (forward_list::_Alloc_traits): Use allocator_traits instead of + __gnu_cxx::__alloc_traits. + * include/bits/forward_list.tcc (_Fwd_list_base::_M_erase_after): + Use node allocator to create and destroy elements. + Backport from mainline 2018-05-29 Jonathan Wakely diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index c37bf01345a3..338e7b3dc6f9 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -274,7 +274,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER struct _Fwd_list_base { protected: - typedef __alloc_rebind<_Alloc, _Tp> _Tp_alloc_type; typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type; typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits; @@ -345,11 +344,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _Node* __node = this->_M_get_node(); __try { - _Tp_alloc_type __a(_M_get_Node_allocator()); - typedef allocator_traits<_Tp_alloc_type> _Alloc_traits; ::new ((void*)__node) _Node; - _Alloc_traits::construct(__a, __node->_M_valptr(), - std::forward<_Args>(__args)...); + _Node_alloc_traits::construct(_M_get_Node_allocator(), + __node->_M_valptr(), + std::forward<_Args>(__args)...); } __catch(...) { @@ -412,10 +410,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typedef _Fwd_list_base<_Tp, _Alloc> _Base; typedef _Fwd_list_node<_Tp> _Node; typedef _Fwd_list_node_base _Node_base; - typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; typedef typename _Base::_Node_alloc_type _Node_alloc_type; typedef typename _Base::_Node_alloc_traits _Node_alloc_traits; - typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Alloc_traits; + typedef allocator_traits<__alloc_rebind<_Alloc, _Tp>> _Alloc_traits; public: // types: diff --git a/libstdc++-v3/include/bits/forward_list.tcc b/libstdc++-v3/include/bits/forward_list.tcc index b823b09e1af3..c852aa1b7162 100644 --- a/libstdc++-v3/include/bits/forward_list.tcc +++ b/libstdc++-v3/include/bits/forward_list.tcc @@ -69,8 +69,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { _Node* __curr = static_cast<_Node*>(__pos->_M_next); __pos->_M_next = __curr->_M_next; - _Tp_alloc_type __a(_M_get_Node_allocator()); - allocator_traits<_Tp_alloc_type>::destroy(__a, __curr->_M_valptr()); + _Node_alloc_traits::destroy(_M_get_Node_allocator(), + __curr->_M_valptr()); __curr->~_Node(); _M_put_node(__curr); return __pos->_M_next; @@ -87,8 +87,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER { _Node* __temp = __curr; __curr = static_cast<_Node*>(__curr->_M_next); - _Tp_alloc_type __a(_M_get_Node_allocator()); - allocator_traits<_Tp_alloc_type>::destroy(__a, __temp->_M_valptr()); + _Node_alloc_traits::destroy(_M_get_Node_allocator(), + __temp->_M_valptr()); __temp->~_Node(); _M_put_node(__temp); }