]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/54075 ([4.7.1] unordered_map insert still slower than 4.6.2)
authorFrançois Dumont <fdumont@gcc.gnu.org>
Thu, 8 Nov 2012 20:16:04 +0000 (20:16 +0000)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Thu, 8 Nov 2012 20:16:04 +0000 (20:16 +0000)
2012-11-08  François Dumont  <fdumont@gcc.gnu.org>

PR libstdc++/54075
* include/bits/hashtable.h (_Hashtable<>::rehash): Reset hash
policy state if no rehash.
* testsuite/23_containers/unordered_set/modifiers/reserve.cc
(test02): New.

From-SVN: r193339

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/hashtable.h
libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/reserve.cc

index db8a1abcc97d2c1d2b6682a2e4e0596c6de4842d..a6567999839424443e3943406a12ce2fd7f6b0e9 100644 (file)
@@ -1,3 +1,11 @@
+2012-11-08  François Dumont  <fdumont@gcc.gnu.org>
+
+       PR libstdc++/54075
+       * include/bits/hashtable.h (_Hashtable<>::rehash): Reset hash
+       policy state if no rehash.
+       * testsuite/23_containers/unordered_set/modifiers/reserve.cc
+       (test02): New.
+
 2012-11-08  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * testsuite/23_containers/unordered_multimap/insert/55028-debug.cc:
index 8ceacabce121f3e0ea3a8f8bf73483eef9d17548..9b2677b098ad19929fed2e048a9f501abee960b6 100644 (file)
@@ -1654,6 +1654,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          // level.
          _M_rehash_policy._M_prev_resize = 0;
        }
+      else
+       // No rehash, restore previous state to keep a consistent state.
+       _M_rehash_policy._M_reset(__saved_state);
     }
 
   template<typename _Key, typename _Value,
index aba6f771d8198ac2d13f1c501c6f8c5c827c45af..41f428a51db1bcd92824a798a741a438212049e3 100644 (file)
@@ -40,8 +40,28 @@ void test01()
     }
 }
 
+void test02()
+{
+  const int N = 1000;
+
+  typedef std::unordered_set<int> Set;
+  Set s;
+  s.reserve(N);
+  s.reserve(N);
+
+  std::size_t bkts = s.bucket_count();
+  for (int i = 0; i != N; ++i)
+    {
+      s.insert(i);
+      // As long as we insert less than the reserved number of elements we
+      // shouldn't experiment any rehash.
+      VERIFY( s.bucket_count() == bkts );
+    }
+}
+
 int main()
 {
   test01();
+  test02();
   return 0;
 }