diff mbox

Use abi_tag attribute on std::list

Message ID 20141003152426.GI4197@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely Oct. 3, 2014, 3:24 p.m. UTC
On 03/10/14 15:49 +0100, Jonathan Wakely wrote:
>On 03/10/14 16:25 +0200, Marc Glisse wrote:
>>Do you mind if I move (in a future patch once yours is committed) 
>>_M_size into _M_impl::_M_node as suggested in PR 61347?
>
>Gah, that's where I had it until earlier this week, and I looked at it
>and wondered why it was in the _List_impl class (because you only need
>one member in there to benefit from the empty base-class
>optimisation).
>
>I will move it back there, since I already have that code on another
>branch, so there's no point making you change the code to match
>something I've already got!

Marc, this is the relative diff to go back to what I had earlier, with
the size in the _List_impl in case you want to aply it locally (the
dg-error tests are off-by-one with this patch)

Comments

Marc Glisse Oct. 3, 2014, 3:32 p.m. UTC | #1
On Fri, 3 Oct 2014, Jonathan Wakely wrote:

> Marc, this is the relative diff to go back to what I had earlier, with
> the size in the _List_impl in case you want to aply it locally (the
> dg-error tests are off-by-one with this patch)

Thanks. For PR 61347, to avoid offsetof, I will actually need to 
change:

- __detail::_List_node_base _M_node;
- size_t _M_size;
+ _List_node<size_t> _M_node;

and store the size in _M_node._M_data. Since I will have to touch it 
anyway, don't feel forced to move it to _M_impl.
diff mbox

Patch

diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h
index 3a56daf..4dbdaf0 100644
--- a/libstdc++-v3/include/bits/stl_list.h
+++ b/libstdc++-v3/include/bits/stl_list.h
@@ -333,6 +333,17 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       : public _Node_alloc_type
       {
 	__detail::_List_node_base _M_node;
+#if _GLIBCXX_USE_CXX11_ABI
+	size_t			  _M_size;
+
+	// return the stored size
+	size_t _M_node_count() const { return _M_size; }
+#else
+	// count the number of nodes
+	size_t _M_node_count() const
+	{ return _S_distance(_M_node._M_next, std::__addressof(_M_node)); }
+#endif
+
 	_List_impl()
 	: _Node_alloc_type(), _M_node()
 	{ }
@@ -350,24 +361,27 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
       _List_impl _M_impl;
 
-#if _GLIBCXX_USE_CXX11_ABI
-      size_t	 _M_size;
+      _List_node<_Tp>*
+      _M_get_node()
+      { return _M_impl._Node_alloc_type::allocate(1); }
+
+      void
+      _M_put_node(_List_node<_Tp>* __p) _GLIBCXX_NOEXCEPT
+      { _M_impl._Node_alloc_type::deallocate(__p, 1); }
 
-      size_t _M_get_size() const { return _M_size; }
+#if _GLIBCXX_USE_CXX11_ABI
+      size_t _M_get_size() const { return _M_impl._M_size; }
 
-      void _M_set_size(size_t __n) { _M_size = __n; }
+      void _M_set_size(size_t __n) { _M_impl._M_size = __n; }
 
-      void _M_inc_size(size_t __n) { _M_size += __n; }
+      void _M_inc_size(size_t __n) { _M_impl._M_size += __n; }
 
-      void _M_dec_size(size_t __n) { _M_size -= __n; }
+      void _M_dec_size(size_t __n) { _M_impl._M_size -= __n; }
 
       size_t
       _M_distance(const __detail::_List_node_base* __first,
 		  const __detail::_List_node_base* __last) const
       { return _S_distance(__first, __last); }
-
-      // return the stored size
-      size_t _M_node_count() const { return _M_size; }
 #else
       // dummy implementations used when the size is not stored
       size_t _M_get_size() const { return 0; }
@@ -375,23 +389,8 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       void _M_inc_size(size_t) { }
       void _M_dec_size(size_t) { }
       size_t _M_distance(const void*, const void*) const { return 0; }
-
-      // count the number of nodes
-      size_t _M_node_count() const
-      {
-	return _S_distance(_M_impl._M_node._M_next,
-			   std::__addressof(_M_impl._M_node));
-      }
 #endif
 
-      _List_node<_Tp>*
-      _M_get_node()
-      { return _M_impl._Node_alloc_type::allocate(1); }
-
-      void
-      _M_put_node(_List_node<_Tp>* __p) _GLIBCXX_NOEXCEPT
-      { _M_impl._Node_alloc_type::deallocate(__p, 1); }
-
   public:
       typedef _Alloc allocator_type;
 
@@ -941,7 +940,7 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       /**  Returns the number of elements in the %list.  */
       size_type
       size() const _GLIBCXX_NOEXCEPT
-      { return this->_M_node_count(); }
+      { return this->_M_impl._M_node_count(); }
 
       /**  Returns the size() of the largest possible %list.  */
       size_type