From patchwork Thu Nov 8 20:21:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Bug, libstdc++/54075, 4.7.1] unordered_map insert still slower than 4.6.2 Date: Thu, 08 Nov 2012 10:21:00 -0000 From: =?utf-8?b?RnJhbsOnb2lzIER1bW9udCA8ZnJzLmR1bW9udEBnbWFpbC5jb20+?= X-Patchwork-Id: 197879 Message-Id: <509C142C.6080907@gmail.com> To: Jonathan Wakely Cc: "paolo.carlini at oracle dot com" , "libstdc++@gcc.gnu.org" , gcc-patches Attached patch applied to trunk and 4.7 branch. 2012-11-08 François Dumont 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. François On 11/08/2012 01:58 AM, Jonathan Wakely wrote: > On 7 November 2012 22:02, François Dumont wrote: >> Ok to commit ? If so, where ? > That patch is OK for trunk and 4.7, thanks. > Index: include/bits/hashtable.h =================================================================== --- include/bits/hashtable.h (revision 193258) +++ include/bits/hashtable.h (working copy) @@ -1597,6 +1597,9 @@ // 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 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; }