This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Minor changes to forward_list
- From: Paolo Carlini <paolo dot carlini at oracle dot com>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 25 Mar 2009 17:44:06 +0100
- Subject: [v3] Minor changes to forward_list
Hi,
tested x86_64-linux, committed to mainline.
Paolo.
//////////////////
2009-03-25 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/forward_list.h (_Fwd_list_node_base<>::
_M_transfer_after, _M_reverse_after): Move out of line...
* include/bits/forward_list.tcc: ... here.
(forward_list<>::reverse): Move inline...
* include/bits/forward_list.h: ... here; minor cosmetic changes.
Index: include/bits/forward_list.h
===================================================================
--- include/bits/forward_list.h (revision 145063)
+++ include/bits/forward_list.h (working copy)
@@ -62,52 +62,23 @@
::other::pointer _Pointer;
typedef typename _Alloc::template rebind<_Fwd_list_node_base<_Alloc> >
::other::const_pointer _Const_pointer;
-
+
_Pointer _M_next;
-
+
_Fwd_list_node_base() : _M_next(0) { }
-
+
static void
swap(_Fwd_list_node_base& __x, _Fwd_list_node_base& __y)
{ std::swap(__x._M_next, __y._M_next); }
-
+
void
- _M_transfer_after(_Pointer __bbegin, _Pointer __bend)
- {
- _Pointer __keep = __bbegin->_M_next;
- if (__bend)
- {
- __bbegin->_M_next = __bend->_M_next;
- __bend->_M_next = this->_M_next;
- }
- else
- __bbegin->_M_next = 0;
- this->_M_next = __keep;
- }
-
+ _M_transfer_after(_Pointer __bbegin);
+
void
- _M_transfer_after(_Pointer __bbegin)
- {
- _Pointer __bend = __bbegin;
- while (__bend && __bend->_M_next)
- __bend = __bend->_M_next;
- _M_transfer_after(__bbegin, __bend);
- }
-
+ _M_transfer_after(_Pointer __bbegin, _Pointer __bend);
+
void
- _M_reverse_after()
- {
- _Pointer __tail = this->_M_next;
- if (!__tail)
- return;
- while (_Pointer __temp = __tail->_M_next)
- {
- _Pointer __keep = this->_M_next;
- this->_M_next = __temp;
- __tail->_M_next = __temp->_M_next;
- this->_M_next->_M_next = __keep;
- }
- }
+ _M_reverse_after();
};
/**
@@ -159,16 +130,16 @@
reference
operator*() const
- { return __static_pointer_cast<_Node*>(this->_M_node)->_M_value; }
+ { return __static_pointer_cast<_Node*>(_M_node)->_M_value; }
pointer
operator->() const
- { return &__static_pointer_cast<_Node*>(this->_M_node)->_M_value; }
+ { return &__static_pointer_cast<_Node*>(_M_node)->_M_value; }
_Self&
operator++()
{
- this->_M_node = this->_M_node->_M_next;
+ _M_node = _M_node->_M_next;
return *this;
}
@@ -176,23 +147,23 @@
operator++(int)
{
_Self __tmp(*this);
- this->_M_node = this->_M_node->_M_next;
+ _M_node = _M_node->_M_next;
return __tmp;
}
bool
operator==(const _Self& __x) const
- { return this->_M_node == __x._M_node; }
+ { return _M_node == __x._M_node; }
bool
operator!=(const _Self& __x) const
- { return this->_M_node != __x._M_node; }
+ { return _M_node != __x._M_node; }
_Self
_M_next() const
{
if (_M_node)
- return _Fwd_list_iterator(this->_M_node->_M_next);
+ return _Fwd_list_iterator(_M_node->_M_next);
else
return _Fwd_list_iterator(0);
}
@@ -230,16 +201,16 @@
reference
operator*() const
- { return __static_pointer_cast<_Node*>(this->_M_node)->_M_value; }
+ { return __static_pointer_cast<_Node*>(_M_node)->_M_value; }
pointer
operator->() const
- { return &__static_pointer_cast<_Node*>(this->_M_node)->_M_value; }
+ { return &__static_pointer_cast<_Node*>(_M_node)->_M_value; }
_Self&
operator++()
{
- this->_M_node = this->_M_node->_M_next;
+ _M_node = _M_node->_M_next;
return *this;
}
@@ -247,23 +218,23 @@
operator++(int)
{
_Self __tmp(*this);
- this->_M_node = this->_M_node->_M_next;
+ _M_node = _M_node->_M_next;
return __tmp;
}
bool
operator==(const _Self& __x) const
- { return this->_M_node == __x._M_node; }
+ { return _M_node == __x._M_node; }
bool
operator!=(const _Self& __x) const
- { return this->_M_node != __x._M_node; }
+ { return _M_node != __x._M_node; }
_Self
_M_next() const
{
if (this->_M_node)
- return _Fwd_list_const_iterator(this->_M_node->_M_next);
+ return _Fwd_list_const_iterator(_M_node->_M_next);
else
return _Fwd_list_const_iterator(0);
}
@@ -777,7 +748,8 @@
reference
front()
{
- _Node* __front = __static_pointer_cast<_Node*>(this->_M_impl._M_head._M_next);
+ _Node* __front =
+ __static_pointer_cast<_Node*>(this->_M_impl._M_head._M_next);
return __front->_M_value;
}
@@ -1229,7 +1201,8 @@
* Reverse the order of elements in the list in linear time.
*/
void
- reverse();
+ reverse()
+ { this->_M_impl._M_head._M_reverse_after(); }
private:
template<typename _Integer>
@@ -1328,7 +1301,7 @@
template<typename _Tp, typename _Alloc>
inline void
swap(forward_list<_Tp, _Alloc>& __lx,
- forward_list<_Tp, _Alloc>&& __ly)
+ forward_list<_Tp, _Alloc>&& __ly)
{ __lx.swap(__ly); }
_GLIBCXX_END_NAMESPACE // namespace std
Index: include/bits/forward_list.tcc
===================================================================
--- include/bits/forward_list.tcc (revision 145063)
+++ include/bits/forward_list.tcc (working copy)
@@ -1,6 +1,6 @@
// <forward_list.tcc> -*- C++ -*-
-// Copyright (C) 2008 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -36,6 +36,50 @@
_GLIBCXX_BEGIN_NAMESPACE(std)
+ template<typename _Alloc>
+ void
+ _Fwd_list_node_base<_Alloc>::
+ _M_transfer_after(_Pointer __bbegin)
+ {
+ _Pointer __bend = __bbegin;
+ while (__bend && __bend->_M_next)
+ __bend = __bend->_M_next;
+ _M_transfer_after(__bbegin, __bend);
+ }
+
+ template<typename _Alloc>
+ void
+ _Fwd_list_node_base<_Alloc>::
+ _M_transfer_after(_Pointer __bbegin, _Pointer __bend)
+ {
+ _Pointer __keep = __bbegin->_M_next;
+ if (__bend)
+ {
+ __bbegin->_M_next = __bend->_M_next;
+ __bend->_M_next = _M_next;
+ }
+ else
+ __bbegin->_M_next = 0;
+ _M_next = __keep;
+ }
+
+ template<typename _Alloc>
+ void
+ _Fwd_list_node_base<_Alloc>::
+ _M_reverse_after()
+ {
+ _Pointer __tail = _M_next;
+ if (!__tail)
+ return;
+ while (_Pointer __temp = __tail->_M_next)
+ {
+ _Pointer __keep = _M_next;
+ _M_next = __temp;
+ __tail->_M_next = __temp->_M_next;
+ _M_next->_M_next = __keep;
+ }
+ }
+
/**
* @brief Sort the singly linked list starting after this node.
* This node is assumed to be an empty head node (of type
@@ -412,12 +456,6 @@
}
template<typename _Tp, typename _Alloc>
- void
- forward_list<_Tp, _Alloc>::
- reverse()
- { this->_M_impl._M_head._M_reverse_after(); }
-
- template<typename _Tp, typename _Alloc>
bool
operator==(const forward_list<_Tp, _Alloc>& __lx,
const forward_list<_Tp, _Alloc>& __ly)