From: Simon Marchi <simon.marchi@polymtl.ca>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Specialize std::hash for ptid_t
Date: Mon, 11 Sep 2023 11:25:09 -0400 [thread overview]
Message-ID: <99e5e4c7-9530-4eaa-8062-c13abb66b7b2@polymtl.ca> (raw)
In-Reply-To: <20230911144718.3425981-1-tromey@adacore.com>
On 9/11/23 10:47, Tom Tromey via Gdb-patches wrote:
> This changes hash_ptid to instead be a specialization of std::hash.
> This makes it a little easier to use with standard containers.
> ---
> gdb/inferior.h | 2 +-
> gdb/regcache.c | 2 +-
> gdbsupport/ptid.h | 8 +++++---
> 3 files changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/gdb/inferior.h b/gdb/inferior.h
> index 04672582984..29c90d15efa 100644
> --- a/gdb/inferior.h
> +++ b/gdb/inferior.h
> @@ -462,7 +462,7 @@ class inferior : public refcounted_object,
>
> /* A map of ptid_t to thread_info*, for average O(1) ptid_t lookup.
> Exited threads do not appear in the map. */
> - std::unordered_map<ptid_t, thread_info *, hash_ptid> ptid_thread_map;
> + std::unordered_map<ptid_t, thread_info *> ptid_thread_map;
>
> /* Returns a range adapter covering the inferior's threads,
> including exited threads. Used like this:
> diff --git a/gdb/regcache.c b/gdb/regcache.c
> index 9b71931bb0b..91b20b7a2a2 100644
> --- a/gdb/regcache.c
> +++ b/gdb/regcache.c
> @@ -329,7 +329,7 @@ reg_buffer::assert_regnum (int regnum) const
> regcaches, associated to different gdbarches). */
>
> using ptid_regcache_map
> - = std::unordered_multimap<ptid_t, regcache_up, hash_ptid>;
> + = std::unordered_multimap<ptid_t, regcache_up>;
>
> /* Type holding regcaches for a given pid. */
>
> diff --git a/gdbsupport/ptid.h b/gdbsupport/ptid.h
> index aa296b83181..96c7d9c8bfd 100644
> --- a/gdbsupport/ptid.h
> +++ b/gdbsupport/ptid.h
> @@ -157,9 +157,10 @@ class ptid_t
> tid_type m_tid;
> };
>
> -/* Functor to hash a ptid. */
> -
> -struct hash_ptid
> +namespace std
> +{
> +template<>
> +struct hash<ptid_t>
> {
> size_t operator() (const ptid_t &ptid) const
> {
> @@ -170,6 +171,7 @@ struct hash_ptid
> + long_hash (ptid.tid ()));
> }
> };
> +}
When searching on that topic, I found some sources advising against
opening namespace std, like this one:
https://quuxplusone.github.io/blog/2021/10/27/dont-reopen-namespace-std/
It can instead be written as:
template<>
struct std::hash<ptid_t>
{
...
};
Not sure if it matters here.
Simon
next prev parent reply other threads:[~2023-09-11 15:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 14:47 Tom Tromey
2023-09-11 15:25 ` Simon Marchi [this message]
2023-09-11 16:35 ` Tom Tromey
2023-09-11 17:14 ` Simon Marchi
2023-09-14 19:14 ` Vaseeharan Vinayagamoorthy
2023-09-14 19:33 ` Tom Tromey
2023-09-14 22:34 ` Vaseeharan Vinayagamoorthy
2023-09-15 0:59 ` Simon Marchi
2023-09-15 13:15 ` Tom Tromey
2023-09-15 13:56 ` Simon Marchi
2023-09-15 16:22 ` Tom Tromey
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=99e5e4c7-9530-4eaa-8062-c13abb66b7b2@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
--cc=tromey@adacore.com \
/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).