This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Remove unordered containers iterators default initialization


Hi

Following N3644 discussion thread here is a patch proposal to remove default zero-initialization of unordered containers iterator. I also took the time to remove default zero-init of nodes _M_nxt pointer.

2013-11-25  François Dumont  <fdumont@gcc.gnu.org>

    * include/bits/hashtable_policy.h (_Hash_node_base): Default
    default constructor.
    (_Node_iterator): Likewise.
    (_Node_const_iterator): Likewise.
    * include/bits/hashtable.h: Adapt.

Tested under Linux x86_64.

Ok to commit ?

François



Index: include/bits/hashtable_policy.h
===================================================================
--- include/bits/hashtable_policy.h	(revision 205288)
+++ include/bits/hashtable_policy.h	(working copy)
@@ -230,7 +230,7 @@
   {
     _Hash_node_base* _M_nxt;
 
-    _Hash_node_base() noexcept : _M_nxt() { }
+    _Hash_node_base() = default;
 
     _Hash_node_base(_Hash_node_base* __next) noexcept : _M_nxt(__next) { }
   };
@@ -306,6 +306,7 @@
 
       __node_type*  _M_cur;
 
+      _Node_iterator_base() = default;
       _Node_iterator_base(__node_type* __p) noexcept
       : _M_cur(__p) { }
 
@@ -348,8 +349,7 @@
       using reference = typename std::conditional<__constant_iterators,
 						  const _Value&, _Value&>::type;
 
-      _Node_iterator() noexcept
-      : __base_type(0) { }
+      _Node_iterator() = default;
 
       explicit
       _Node_iterator(__node_type* __p) noexcept
@@ -396,8 +396,7 @@
       typedef const _Value*				pointer;
       typedef const _Value&				reference;
 
-      _Node_const_iterator() noexcept
-      : __base_type(0) { }
+      _Node_const_iterator() = default;
 
       explicit
       _Node_const_iterator(__node_type* __p) noexcept
Index: include/bits/hashtable.h
===================================================================
--- include/bits/hashtable.h	(revision 205288)
+++ include/bits/hashtable.h	(working copy)
@@ -788,6 +788,7 @@
       __map_base(),
       __rehash_base(),
       __hashtable_alloc(__node_alloc_type(__a)),
+      _M_before_begin(nullptr),
       _M_element_count(0),
       _M_rehash_policy()
     {
@@ -811,6 +812,7 @@
 	__map_base(),
 	__rehash_base(),
 	__hashtable_alloc(__node_alloc_type(__a)),
+	_M_before_begin(nullptr),
 	_M_element_count(0),
 	_M_rehash_policy()
       {
@@ -952,6 +954,7 @@
 	    // _M_before_begin.
 	    __node_type* __ht_n = __ht._M_begin();
 	    __node_type* __this_n = __node_gen(__ht_n);
+	    __this_n->_M_nxt = nullptr;
 	    this->_M_copy_code(__this_n, __ht_n);
 	    _M_before_begin._M_nxt = __this_n;
 	    _M_buckets[_M_bucket_index(__this_n)] = &_M_before_begin;
@@ -961,6 +964,7 @@
 	    for (__ht_n = __ht_n->_M_next(); __ht_n; __ht_n = __ht_n->_M_next())
 	      {
 		__this_n = __node_gen(__ht_n);
+		__this_n->_M_nxt = nullptr;
 		__prev_n->_M_nxt = __this_n;
 		this->_M_copy_code(__this_n, __ht_n);
 		size_type __bkt = _M_bucket_index(__this_n);
@@ -1092,6 +1096,7 @@
 	__node_alloc_traits::_S_select_on_copy(__ht._M_node_allocator())),
       _M_buckets(),
       _M_bucket_count(__ht._M_bucket_count),
+      _M_before_begin(nullptr),
       _M_element_count(__ht._M_element_count),
       _M_rehash_policy(__ht._M_rehash_policy)
     {
@@ -1137,6 +1142,7 @@
       __hashtable_alloc(__node_alloc_type(__a)),
       _M_buckets(),
       _M_bucket_count(__ht._M_bucket_count),
+      _M_before_begin(nullptr),
       _M_element_count(__ht._M_element_count),
       _M_rehash_policy(__ht._M_rehash_policy)
     {
@@ -1158,6 +1164,7 @@
       __hashtable_alloc(__node_alloc_type(__a)),
       _M_buckets(),
       _M_bucket_count(__ht._M_bucket_count),
+      _M_before_begin(nullptr),
       _M_element_count(__ht._M_element_count),
       _M_rehash_policy(__ht._M_rehash_policy)
     {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]