public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR libstdc++/87135 Rehash only when necessary (LWG2156)
Date: Tue, 18 Sep 2018 08:46:00 -0000	[thread overview]
Message-ID: <20180918084159.GV23172@redhat.com> (raw)
In-Reply-To: <1ad7ad86-0f0c-e8b0-8f29-2b5303718988@gmail.com>

On 13/09/18 07:49 +0200, François Dumont wrote:
>All changes limited to hashtable_c++0x.cc file.
>
>_Prime_rehash_policy::_M_next_bkt now really does what its comment was 
>declaring that is to say:
>  // Return a prime no smaller than n.
>
>_Prime_rehash_policy::_M_need_rehash rehash only when _M_next_size is 
>exceeded, not only when it is reach.
>
>    PR libstdc++/87135
>    * src/c++11/hashtable_c++0x.cc:
>    (_Prime_rehash_policy::_M_next_bkt): Return a prime no smaller than
>    requested size, but not necessarily greater.
>    (_Prime_rehash_policy::_M_need_rehash): Rehash only if target size is
>    strictly greater than next resize threshold.
>    * testsuite/23_containers/unordered_map/modifiers/reserve.cc: 
>Adapt test
>    to validate that there is no rehash as long as number of insertion is
>    lower or equal to the reserved number of elements.
>
>unordered_map tests successful, ok to commit once all other tests 
>completed ?
>
>François

>diff --git a/libstdc++-v3/src/c++11/hashtable_c++0x.cc b/libstdc++-v3/src/c++11/hashtable_c++0x.cc
>index a776a8506fe..ec6031b3f5b 100644
>--- a/libstdc++-v3/src/c++11/hashtable_c++0x.cc
>+++ b/libstdc++-v3/src/c++11/hashtable_c++0x.cc
>@@ -46,10 +46,10 @@ namespace __detail
>   {
>     // Optimize lookups involving the first elements of __prime_list.
>     // (useful to speed-up, eg, constructors)
>-    static const unsigned char __fast_bkt[13]
>-      = { 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11, 13, 13 };
>+    static const unsigned char __fast_bkt[]
>+      = { 2, 2, 2, 3, 5, 5, 7, 7, 11, 11, 11, 11, 13, 13 };
> 
>-    if (__n <= 12)
>+    if (__n < sizeof(__fast_bkt) / sizeof(unsigned char))

sizeof(unsigned char) is defined to be 1, always.

I think this should be just sizeof(__fast_bkt), or if you're trying to
guard against the type of __fast_bkt changing, then use
sizeof(__fast_bkt) / sizeof(__fast_bkt[0]))

OK for trunk with either of those, instead of sizeof(unsigned char).

Thanks.


  reply	other threads:[~2018-09-18  8:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-13  6:43 François Dumont
2018-09-18  8:46 ` Jonathan Wakely [this message]
2018-09-18 21:24   ` François Dumont
2018-09-19  9:16     ` Jonathan Wakely
2018-09-19 11:21     ` Jonathan Wakely
2018-09-19 16:24       ` François Dumont
2018-09-21 16:17       ` François Dumont
2018-09-21 17:13         ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180918084159.GV23172@redhat.com \
    --to=jwakely@redhat.com \
    --cc=frs.dumont@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).