public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Hide _S_n_primes from user code
@ 2015-04-22 19:39 François Dumont
  2015-04-22 20:11 ` François Dumont
  2015-04-22 20:13 ` Marek Polacek
  0 siblings, 2 replies; 4+ messages in thread
From: François Dumont @ 2015-04-22 19:39 UTC (permalink / raw)
  To: libstdc++, gcc-patches

Hello

     Here is a rather trivial patch, just code cleanup. Since we export 
_Prime_rehash_policy we do not need to expose the _S_n_primes anymore.

     * include/bits/hashtable_policy.h (_Prime_rehash_policy::_S_n_primes):
     Delete.
     * src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy::_M_next_bkt):
     Remove usage of latter and compute size of the prime numbers array
     locally.

Tested under Linux x86_64.

Ok to commit ?

François

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Hide _S_n_primes from user code
  2015-04-22 19:39 Hide _S_n_primes from user code François Dumont
@ 2015-04-22 20:11 ` François Dumont
  2015-04-27 11:32   ` Jonathan Wakely
  2015-04-22 20:13 ` Marek Polacek
  1 sibling, 1 reply; 4+ messages in thread
From: François Dumont @ 2015-04-22 20:11 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

With the patch this time.


On 22/04/2015 21:39, François Dumont wrote:
> Hello
>
>     Here is a rather trivial patch, just code cleanup. Since we export 
> _Prime_rehash_policy we do not need to expose the _S_n_primes anymore.
>
>     * include/bits/hashtable_policy.h 
> (_Prime_rehash_policy::_S_n_primes):
>     Delete.
>     * src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy::_M_next_bkt):
>     Remove usage of latter and compute size of the prime numbers array
>     locally.
>
> Tested under Linux x86_64.
>
> Ok to commit ?
>
> François
>


[-- Attachment #2: hashtable.patch --]
[-- Type: text/x-patch, Size: 1215 bytes --]

diff --git a/libstdc++-v3/include/bits/hashtable_policy.h b/libstdc++-v3/include/bits/hashtable_policy.h
index 14bcca6..a9ad7dd 100644
--- a/libstdc++-v3/include/bits/hashtable_policy.h
+++ b/libstdc++-v3/include/bits/hashtable_policy.h
@@ -495,8 +495,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _M_reset(_State __state)
     { _M_next_resize = __state; }
 
-    enum { _S_n_primes = sizeof(unsigned long) != 8 ? 256 : 256 + 48 };
-
     static const std::size_t _S_growth_factor = 2;
 
     float		_M_max_load_factor;
diff --git a/libstdc++-v3/src/c++11/hashtable_c++0x.cc b/libstdc++-v3/src/c++11/hashtable_c++0x.cc
index 22de51b..69f999f 100644
--- a/libstdc++-v3/src/c++11/hashtable_c++0x.cc
+++ b/libstdc++-v3/src/c++11/hashtable_c++0x.cc
@@ -56,8 +56,10 @@ namespace __detail
 	return __fast_bkt[__n];
       }
 
+    constexpr auto __n_primes
+      = sizeof(__prime_list) / sizeof(unsigned long) - 1;
     const unsigned long* __next_bkt =
-      std::lower_bound(__prime_list + 5, __prime_list + _S_n_primes, __n);
+      std::lower_bound(__prime_list + 5, __prime_list + __n_primes, __n);
     _M_next_resize =
       __builtin_ceil(*__next_bkt * (long double)_M_max_load_factor);
     return *__next_bkt;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Hide _S_n_primes from user code
  2015-04-22 19:39 Hide _S_n_primes from user code François Dumont
  2015-04-22 20:11 ` François Dumont
@ 2015-04-22 20:13 ` Marek Polacek
  1 sibling, 0 replies; 4+ messages in thread
From: Marek Polacek @ 2015-04-22 20:13 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On Wed, Apr 22, 2015 at 09:39:48PM +0200, François Dumont wrote:
> Hello
> 
>     Here is a rather trivial patch, just code cleanup. Since we export
> _Prime_rehash_policy we do not need to expose the _S_n_primes anymore.
> 
>     * include/bits/hashtable_policy.h (_Prime_rehash_policy::_S_n_primes):
>     Delete.
>     * src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy::_M_next_bkt):
>     Remove usage of latter and compute size of the prime numbers array
>     locally.
> 
> Tested under Linux x86_64.
> 
> Ok to commit ?

The patch is missing :).

	Marek

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Hide _S_n_primes from user code
  2015-04-22 20:11 ` François Dumont
@ 2015-04-27 11:32   ` Jonathan Wakely
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2015-04-27 11:32 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On 22/04/15 22:11 +0200, François Dumont wrote:
>+    constexpr auto __n_primes
>+      = sizeof(__prime_list) / sizeof(unsigned long) - 1;

Normally I'd say

        sizeof(__prime_list) / sizeof(*__prime_list) - 1

would be better, but since it's very unlikely we'll change the element
type in the array what you have should be safe.

OK for trunk.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-27 11:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-22 19:39 Hide _S_n_primes from user code François Dumont
2015-04-22 20:11 ` François Dumont
2015-04-27 11:32   ` Jonathan Wakely
2015-04-22 20:13 ` Marek Polacek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).