From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: Jonathan Wakely <jwakely.gcc@gmail.com>,
libstdc++ <libstdc++@gcc.gnu.org>,
gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Hashtable PR96088
Date: Mon, 24 May 2021 12:19:39 +0100 [thread overview]
Message-ID: <YKuLy7QJ9sgz0uqJ@redhat.com> (raw)
In-Reply-To: <abec02ff-4343-21de-59ed-a193999426dd@gmail.com>
On 22/05/21 18:35 +0200, François Dumont wrote:
>This was indeed the right approach.
>
> The only minor drawback is that __is_noexcept_invocable<> combines
>noexcept qualification of the conversion and of the hash functor. So
>if the hash functor is not noexcept we could end up creating
>temporaries for nothing.
>
> So I've eventually used this condition:
>
>__and_<__is_nothrow_invocable<_Hash&, const key_type&>,
> __not_<__is_nothrow_invocable<_Hash&, _Kt>>>::value,
>
> so that we do not create a temporary key_type if invoking _Hash
>with it can still throw.
>
> libstdc++: Limit allocation on iterator insertion in Hashtable [PR
>96088]
>
> When inserting into unordered_multiset or unordered_multimap first
>instantiate
> the node to store and compute the hash code from it to avoid a
>potential
> intermediate key_type instantiation.
>
> When inserting into unordered_set or unordered_map check if
>invoking the hash
> functor with container key_type is noexcept and invoking the same
>hash functor
> with key part of the iterator value_type can throw. In this case
>create a
> temporary key_type instance at Hashtable level and use it to
>compute the hash
> code. This temporary instance is moved to the final storage
>location if needed.
>
> libstdc++-v3/ChangeLog:
>
> PR libstdc++/96088
> * include/bits/hashtable_policy.h (_Select2nd): New.
> (_NodeBuilder<>): New.
> (_ReuseOrAllocNode<>::operator()): Use variadic template args.
> (_AllocNode<>::operator()): Likewise.
> * include/bits/hashtable.h
> (_Hashtable<>::__node_builder_t): New.
>(_Hashtable<>::_M_insert_unique<>(_Kt&&, _Arg&&, const _NodeGenerator&)):
> New.
> (_Hashtable<>::_S_forward_key): New.
> (_Hashtable<>::_M_insert): Use latter.
> (_Hashtable<>::_M_insert(const_iterator, _Arg&&, const
>_NodeGenerator&, false_type)):
> Instantiate node first, compute hash code second.
> * testsuite/23_containers/unordered_map/96088.cc: New test.
> * testsuite/23_containers/unordered_multimap/96088.cc: New
>test.
> * testsuite/23_containers/unordered_multiset/96088.cc: New
>test.
> * testsuite/23_containers/unordered_set/96088.cc: New test.
> * testsuite/util/replacement_memory_operators.h
> (counter::_M_increment): New.
> (counter::_M_decrement): New.
> (counter::reset()): New.
>
>Tested under Linux x64.
>
>Ok to commit ?
OK for trunk, thanks.
next prev parent reply other threads:[~2021-05-24 11:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-01 12:36 Hashtable PR96088 Work in Progress François Dumont
2020-10-17 16:21 ` [PATCH] Hashtable PR96088 François Dumont
2020-10-24 14:25 ` François Dumont
2020-12-04 9:10 ` François Dumont
2021-05-06 20:03 ` François Dumont
2021-05-17 19:24 ` François Dumont
2021-05-20 16:44 ` Jonathan Wakely
2021-05-21 5:55 ` François Dumont
2021-05-21 6:48 ` Jonathan Wakely
2021-05-21 6:55 ` Jonathan Wakely
2021-05-22 16:35 ` François Dumont
2021-05-24 11:19 ` Jonathan Wakely [this message]
2021-06-01 17:45 ` Jonathan Wakely
2021-06-01 17:47 ` Jonathan Wakely
2021-06-01 18:10 ` Jonathan Wakely
2021-06-01 20:00 ` François Dumont
2021-06-02 12:35 ` Jonathan Wakely
2021-05-24 9:31 ` François Dumont
2021-05-24 11:18 ` 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=YKuLy7QJ9sgz0uqJ@redhat.com \
--to=jwakely@redhat.com \
--cc=frs.dumont@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jwakely.gcc@gmail.com \
--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).