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
This commit is contained in:
Paolo Carlini 2011-09-06 10:22:21 +00:00 committed by Paolo Carlini
parent 1255c03ad5
commit 4cdccf2665
2 changed files with 15 additions and 2 deletions

View File

@ -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::

View File

@ -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;