diff options
author | Paolo Carlini <paolo.carlini@oracle.com> | 2011-09-06 10:22:21 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2011-09-06 10:22:21 +0000 |
commit | 4cdccf26659e2463f0c1e06da20cb21ea612b391 (patch) | |
tree | 2a1a28ed2b59409e72c202f970d6a7391742f27a | |
parent | 1255c03ad53e732fb5abe39878429c30e758e701 (diff) | |
download | gcc-4cdccf26659e2463f0c1e06da20cb21ea612b391.zip gcc-4cdccf26659e2463f0c1e06da20cb21ea612b391.tar.gz gcc-4cdccf26659e2463f0c1e06da20cb21ea612b391.tar.bz2 |
re PR libstdc++/50257 ([C++0x] unordered_map slow initialization due to huge __prime_list)
2011-09-06 Paolo Carlini <paolo.carlini@oracle.com>
PR libstdc++/50257
* include/bits/hashtable_policy.h (_Prime_rehash_policy::
_M_next_bkt): Optimize for small argument.
From-SVN: r178581
-rw-r--r-- | libstdc++-v3/ChangeLog | 6 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/hashtable_policy.h | 11 |
2 files changed, 15 insertions, 2 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 5d34b2b..d0c1b11 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2011-09-06 Paolo Carlini <paolo.carlini@oracle.com> + + PR libstdc++/50257 + * include/bits/hashtable_policy.h (_Prime_rehash_policy:: + _M_next_bkt): Optimize for small argument. + 2011-09-02 François Dumont <fdumont@gcc.gnu.org> * testsuite/util/testsuite_allocator.h (tracker_allocator_counter:: diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h index ab34463..08a6dcd 100644 --- a/libstdc++-v3/include/bits/hashtable_policy.h +++ b/libstdc++-v3/include/bits/hashtable_policy.h @@ -427,8 +427,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Prime_rehash_policy:: _M_next_bkt(std::size_t __n) const { - const unsigned long __p = *std::lower_bound(__prime_list, __prime_list - + _S_n_primes, __n); + // Optimize lookups involving the first elements of __prime_list. + // (useful to speed-up, eg, constructors) + static const unsigned char __fastbkt[12] + = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11 }; + + const unsigned long __p + = __n <= 11 ? __fastbkt[__n] + : *std::lower_bound(__prime_list + 5, + __prime_list + _S_n_primes, __n); _M_next_resize = static_cast<std::size_t>(__builtin_floor(__p * _M_max_load_factor)); return __p; |