Patchwork [v3] libstdc++/50257

login
register
mail settings
Submitter Paolo Carlini
Date Sept. 6, 2011, 10:26 a.m.
Message ID <4E65F542.9010400@oracle.com>
Download mbox | patch
Permalink /patch/113526/
State New
Headers show

Comments

Paolo Carlini - Sept. 6, 2011, 10:26 a.m.
Hi,

tested x86_64-linux, committed to mainline. See audit trail for details...

Thanks,
Paolo.

/////////////////////
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.

Patch

Index: include/bits/hashtable_policy.h
===================================================================
--- include/bits/hashtable_policy.h	(revision 178574)
+++ include/bits/hashtable_policy.h	(working copy)
@@ -427,8 +427,15 @@ 
   _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;