]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/50257 ([C++0x] unordered_map slow initialization due to huge __prime_...
authorPaolo Carlini <paolo.carlini@oracle.com>
Tue, 6 Sep 2011 10:22:21 +0000 (10:22 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Tue, 6 Sep 2011 10:22:21 +0000 (10:22 +0000)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/hashtable_policy.h

index 5d34b2b419f7efaf73cdd0585e26dbb6b032a972..d0c1b11c4eb87453f6c64f2222cd24aea9577651 100644 (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::
index ab34463475bb6dba1636be432a656300e737b593..08a6dcd39a26f6eb1fbe40340d869cf5baa728ff 100644 (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;