diff mbox

New hashtable power 2 rehash policy

Message ID 20160525091709.GD14158@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely May 25, 2016, 9:17 a.m. UTC
On 25/05/16 10:15 +0200, Andreas Schwab wrote:
>François Dumont <frs.dumont@gmail.com> writes:
>
>>     * include/bits/c++config (_GLIBCXX14_USE_CONSTEXPR): New.
>
>FAIL: ext/profile/mutex_extensions_neg.cc  (test for errors, line 324)
>FAIL: ext/profile/mutex_extensions_neg.cc (test for excess errors)
>Excess errors:
>/usr/local/gcc/gcc-20160525/Build/ia64-suse-linux/libstdc++-v3/include/ia64-suse-linux/bits/c++config.h:326:4: error: #error illegal use of multiple inlined namespaces

Fixed with this patch (we don't need the new macro anyway, so it can
be simply removed).

The mutable specifier on _Power2_rehash_policy::_M_next_bkt is also
unnecessary, because the member functions that change it don't need to
be const. It's best to avoid mutable wherever possible, since in
general modifying member data in const functions leads to data races.
In this case it doesn't, because the const member functions are only
called on non-const objects, so the functions don't need to be const.

I'll commit to trunk when testing finishes.
diff mbox

Patch

commit 327e9529040b5c044339e168e5577e1c3d3d4934
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 25 09:43:00 2016 +0100

    Remove _GLIBCXX14_USE_CONSTEXPR
    
    	* include/bits/c++config (_GLIBCXX14_USE_CONSTEXPR): Remove it.
    	* include/bits/hashtable_policy.h (_Power2_rehash_policy::_M_next_bkt):
    	Remove const qualification on function. Replace
    	_GLIBCXX14_USE_CONSTEXPR on automatic variables with const.
    	(_Power2_rehash_policy::_M_need_rehash): Remove const qualification.
    	(_Power2_rehash_policy::_M_next_bkt): Remove mutable specifier.

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 78353ae..57024e4 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -106,10 +106,8 @@ 
 #ifndef _GLIBCXX14_CONSTEXPR
 # if __cplusplus >= 201402L
 #  define _GLIBCXX14_CONSTEXPR constexpr
-#  define _GLIBCXX14_USE_CONSTEXPR constexpr
 # else
 #  define _GLIBCXX14_CONSTEXPR
-#  define _GLIBCXX14_USE_CONSTEXPR const
 # endif
 #endif
 
diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index 0b317c3..759d0ca 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -557,13 +557,10 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     // Return a bucket size no smaller than n (as long as n is not above the
     // highest power of 2).
     std::size_t
-    _M_next_bkt(std::size_t __n) const noexcept
+    _M_next_bkt(std::size_t __n) noexcept
     {
-      _GLIBCXX14_USE_CONSTEXPR size_t __max_width
-	= std::min<size_t>(sizeof(size_t), 8);
-      _GLIBCXX14_USE_CONSTEXPR auto __max_bkt
-	= std::size_t(1) << (__max_width * __CHAR_BIT__ - 1);
-
+      const auto __max_width = std::min<size_t>(sizeof(size_t), 8);
+      const auto __max_bkt = size_t(1) << (__max_width * __CHAR_BIT__ - 1);
       std::size_t __res = __clp2(__n);
 
       if (__res == __n)
@@ -595,7 +592,7 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     // is the new bucket count.  If not, return make_pair(false, 0).
     std::pair<bool, std::size_t>
     _M_need_rehash(std::size_t __n_bkt, std::size_t __n_elt,
-		   std::size_t __n_ins) const noexcept
+		   std::size_t __n_ins) noexcept
     {
       if (__n_elt + __n_ins >= _M_next_resize)
 	{
@@ -630,8 +627,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
     static const std::size_t _S_growth_factor = 2;
 
-    float		_M_max_load_factor;
-    mutable std::size_t	_M_next_resize;
+    float	_M_max_load_factor;
+    std::size_t	_M_next_resize;
   };
 
   // Base classes for std::_Hashtable.  We define these base classes