Commit 55500f5d by François Dumont

stl_list.h [!_GLIBCXX_INLINE_VERSION](_List_base<>::_S_distance): Remove.

2017-08-24  François Dumont  <fdumont@gcc.gnu.org>

	* include/bits/stl_list.h
	[!_GLIBCXX_INLINE_VERSION](_List_base<>::_S_distance): Remove.
	(_List_impl(_Node_alloc_type&&, _List_impl&&)): New.
	(_List_base(_Node_alloc_type&&, _List_base&&)): New, use latter.
	[!_GLIBCXX_INLINE_VERSION](_List_base(_Node_alloc_type&&,_List_base&&)):
	Remove.
	(_List_base(_Node_alloc_type&&)): New.
	[!_GLIBCXX_INLINE_VERSION](_List_base<>::_M_distance): Remove.
	[!_GLIBCXX_INLINE_VERSION](_List_base<>::_M_node_count): Remove.
	(list<>::_M_node_count): New.
	(list<>::size()): Adapt to call latter.
	(list<>::_S_distance(const_iterator, const_iterator)): New.
	(list<>::splice(iterator, list&, const_iterator, const_iterator)):
	Adapt to call latter.
	(list(list&&, const allocator_type&, true_type)): New.
	(list(list&&, const allocator_type&, false_type)): New.
	(list(list&&, const allocator_type&)): Adapt to call latters.

From-SVN: r251342
parent db1e5f32
2017-08-24 François Dumont <fdumont@gcc.gnu.org>
* include/bits/stl_list.h
[!_GLIBCXX_INLINE_VERSION](_List_base<>::_S_distance): Remove.
(_List_impl(_Node_alloc_type&&, _List_impl&&)): New.
(_List_base(_Node_alloc_type&&, _List_base&&)): New, use latter.
[!_GLIBCXX_INLINE_VERSION](_List_base(_Node_alloc_type&&,_List_base&&)):
Remove.
(_List_base(_Node_alloc_type&&)): New.
[!_GLIBCXX_INLINE_VERSION](_List_base<>::_M_distance): Remove.
[!_GLIBCXX_INLINE_VERSION](_List_base<>::_M_node_count): Remove.
(list<>::_M_node_count): New.
(list<>::size()): Adapt to call latter.
(list<>::_S_distance(const_iterator, const_iterator)): New.
(list<>::splice(iterator, list&, const_iterator, const_iterator)):
Adapt to call latter.
(list(list&&, const allocator_type&, true_type)): New.
(list(list&&, const allocator_type&, false_type)): New.
(list(list&&, const allocator_type&)): Adapt to call latters.
2017-08-21 Jonathan Wakely <jwakely@redhat.com> 2017-08-21 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/81912 PR libstdc++/81912
......
...@@ -364,6 +364,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -364,6 +364,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
rebind<_List_node<_Tp> >::other _Node_alloc_type; rebind<_List_node<_Tp> >::other _Node_alloc_type;
typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits; typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;
#if !_GLIBCXX_INLINE_VERSION
static size_t static size_t
_S_distance(const __detail::_List_node_base* __first, _S_distance(const __detail::_List_node_base* __first,
const __detail::_List_node_base* __last) const __detail::_List_node_base* __last)
...@@ -376,6 +377,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -376,6 +377,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
} }
return __n; return __n;
} }
#endif
struct _List_impl struct _List_impl
: public _Node_alloc_type : public _Node_alloc_type
...@@ -393,6 +395,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -393,6 +395,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
_List_impl(_List_impl&&) = default; _List_impl(_List_impl&&) = default;
_List_impl(_Node_alloc_type&& __a, _List_impl&& __x)
: _Node_alloc_type(std::move(__a)), _M_node(std::move(__x._M_node))
{ }
_List_impl(_Node_alloc_type&& __a) noexcept _List_impl(_Node_alloc_type&& __a) noexcept
: _Node_alloc_type(std::move(__a)) : _Node_alloc_type(std::move(__a))
{ } { }
...@@ -410,6 +416,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -410,6 +416,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
void _M_dec_size(size_t __n) { _M_impl._M_node._M_size -= __n; } void _M_dec_size(size_t __n) { _M_impl._M_node._M_size -= __n; }
# if !_GLIBCXX_INLINE_VERSION
size_t size_t
_M_distance(const __detail::_List_node_base* __first, _M_distance(const __detail::_List_node_base* __first,
const __detail::_List_node_base* __last) const const __detail::_List_node_base* __last) const
...@@ -417,12 +424,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -417,12 +424,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
// return the stored size // return the stored size
size_t _M_node_count() const { return _M_get_size(); } size_t _M_node_count() const { return _M_get_size(); }
# endif
#else #else
// dummy implementations used when the size is not stored // dummy implementations used when the size is not stored
size_t _M_get_size() const { return 0; } size_t _M_get_size() const { return 0; }
void _M_set_size(size_t) { } void _M_set_size(size_t) { }
void _M_inc_size(size_t) { } void _M_inc_size(size_t) { }
void _M_dec_size(size_t) { } void _M_dec_size(size_t) { }
# if !_GLIBCXX_INLINE_VERSION
size_t _M_distance(const void*, const void*) const { return 0; } size_t _M_distance(const void*, const void*) const { return 0; }
// count the number of nodes // count the number of nodes
...@@ -431,6 +441,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -431,6 +441,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
return _S_distance(_M_impl._M_node._M_next, return _S_distance(_M_impl._M_node._M_next,
std::__addressof(_M_impl._M_node)); std::__addressof(_M_impl._M_node));
} }
# endif
#endif #endif
typename _Node_alloc_traits::pointer typename _Node_alloc_traits::pointer
...@@ -465,6 +476,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -465,6 +476,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
_List_base(_List_base&&) = default; _List_base(_List_base&&) = default;
# if !_GLIBCXX_INLINE_VERSION
_List_base(_List_base&& __x, _Node_alloc_type&& __a) _List_base(_List_base&& __x, _Node_alloc_type&& __a)
: _M_impl(std::move(__a)) : _M_impl(std::move(__a))
{ {
...@@ -472,6 +484,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -472,6 +484,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_M_move_nodes(std::move(__x)); _M_move_nodes(std::move(__x));
// else caller must move individual elements. // else caller must move individual elements.
} }
# endif
// Used when allocator is_always_equal.
_List_base(_Node_alloc_type&& __a, _List_base&& __x)
: _M_impl(std::move(__a), std::move(__x._M_impl))
{ }
// Used when allocator !is_always_equal.
_List_base(_Node_alloc_type&& __a)
: _M_impl(std::move(__a))
{ }
void void
_M_move_nodes(_List_base&& __x) _M_move_nodes(_List_base&& __x)
...@@ -616,6 +639,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -616,6 +639,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
} }
#endif #endif
#if _GLIBCXX_USE_CXX11_ABI
static size_t
_S_distance(const_iterator __first, const_iterator __last)
{ return std::distance(__first, __last); }
// return the stored size
size_t
_M_node_count() const
{ return this->_M_get_size(); }
#else
// dummy implementations used when the size is not stored
static size_t
_S_distance(const_iterator, const_iterator)
{ return 0; }
// count the number of nodes
size_t
_M_node_count() const
{ return std::distance(begin(), end()); }
#endif
public: public:
// [23.2.2.1] construct/copy/destroy // [23.2.2.1] construct/copy/destroy
// (assign() and get_allocator() are also listed in this section) // (assign() and get_allocator() are also listed in this section)
...@@ -718,15 +762,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -718,15 +762,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
: _Base(_Node_alloc_type(__a)) : _Base(_Node_alloc_type(__a))
{ _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); } { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); }
list(list&& __x, const allocator_type& __a) private:
noexcept(_Node_alloc_traits::_S_always_equal()) list(list&& __x, const allocator_type& __a, true_type) noexcept
: _Base(std::move(__x), _Node_alloc_type(__a)) : _Base(_Node_alloc_type(__a), std::move(__x))
{ }
list(list&& __x, const allocator_type& __a, false_type)
: _Base(_Node_alloc_type(__a))
{ {
// If __x is not empty it means its allocator is not equal to __a, if (__x._M_get_Node_allocator() == this->_M_get_Node_allocator())
// so we need to move from each element individually. this->_M_move_nodes(std::move(__x));
insert(begin(), std::__make_move_if_noexcept_iterator(__x.begin()), else
std::__make_move_if_noexcept_iterator(__x.end())); insert(begin(), std::__make_move_if_noexcept_iterator(__x.begin()),
std::__make_move_if_noexcept_iterator(__x.end()));
} }
public:
list(list&& __x, const allocator_type& __a)
noexcept(_Node_alloc_traits::_S_always_equal())
: list(std::move(__x), __a,
typename _Node_alloc_traits::is_always_equal{})
{ }
#endif #endif
/** /**
...@@ -1000,7 +1056,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1000,7 +1056,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
/** Returns the number of elements in the %list. */ /** Returns the number of elements in the %list. */
size_type size_type
size() const _GLIBCXX_NOEXCEPT size() const _GLIBCXX_NOEXCEPT
{ return this->_M_node_count(); } { return _M_node_count(); }
/** Returns the size() of the largest possible %list. */ /** Returns the size() of the largest possible %list. */
size_type size_type
...@@ -1578,7 +1634,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 ...@@ -1578,7 +1634,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
if (this != std::__addressof(__x)) if (this != std::__addressof(__x))
_M_check_equal_allocators(__x); _M_check_equal_allocators(__x);
size_t __n = this->_M_distance(__first._M_node, __last._M_node); size_t __n = _S_distance(__first, __last);
this->_M_inc_size(__n); this->_M_inc_size(__n);
__x._M_dec_size(__n); __x._M_dec_size(__n);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment