aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorFrançois Dumont <fdumont@gcc.gnu.org>2012-11-08 20:16:04 +0000
committerFrançois Dumont <fdumont@gcc.gnu.org>2012-11-08 20:16:04 +0000
commitecf07a67d0e8cc33b780783d9996a0e91a6239a2 (patch)
tree1a19c993748ad806a6a8754863138e86283b4eca /libstdc++-v3
parent68a559809331d754474191b2272cc7e4a960b65c (diff)
downloadgcc-ecf07a67d0e8cc33b780783d9996a0e91a6239a2.zip
gcc-ecf07a67d0e8cc33b780783d9996a0e91a6239a2.tar.gz
gcc-ecf07a67d0e8cc33b780783d9996a0e91a6239a2.tar.bz2
re PR libstdc++/54075 ([4.7.1] unordered_map insert still slower than 4.6.2)
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
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/bits/hashtable.h3
-rw-r--r--libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/reserve.cc20
3 files changed, 31 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index db8a1ab..a656799 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -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:
diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h
index 8ceacab..9b2677b 100644
--- a/libstdc++-v3/include/bits/hashtable.h
+++ b/libstdc++-v3/include/bits/hashtable.h
@@ -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,
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/reserve.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/reserve.cc
index aba6f77..41f428a 100644
--- a/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/reserve.cc
+++ b/libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/reserve.cc
@@ -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;
}