This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 1/2] gdb: Convert completion tracker to use std types
- From: "Christian Biesinger via gdb-patches" <gdb-patches at sourceware dot org>
- To: Tom Tromey <tom at tromey dot com>
- Cc: Andrew Burgess <andrew dot burgess at embecosm dot com>, gdb-patches <gdb-patches at sourceware dot org>
- Date: Fri, 24 Jan 2020 20:17:17 +0100
- Subject: Re: [PATCH 1/2] gdb: Convert completion tracker to use std types
- References: <cover.1577481992.git.andrew.burgess@embecosm.com> <c9cf5478c7c3d4fc0af6f484d8acd007fd7bb8b2.1577481993.git.andrew.burgess@embecosm.com> <87pnf88z3o.fsf@tromey.com>
- Reply-to: Christian Biesinger <cbiesinger at google dot com>
On Fri, Jan 24, 2020, 20:14 Tom Tromey <tom@tromey.com> wrote:
> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
>
> Andrew> For now then I'm holding the raw 'char *' within the unordered_map,
> Andrew> and rely on the completion_tracker object to delete the data if
> Andrew> needed, or to ensure that the data is passed over to readline,
> which
> Andrew> will do the deletion for us.
>
> Seems reasonable enough.
>
> Andrew> + for (const auto &p : m_entries_hash)
> Andrew> + {
> Andrew> + xfree ((char *) p.first);
> Andrew> + xfree ((char *) p.second);
>
> Maybe const_cast would be better?
>
> Andrew> + /* A map of completions. The key is the completion, and the
> value is the
> Andrew> + string to be used to compute the lowest common denominator.
> Both the
> Andrew> + key and the value are owned by the completion_tracker class
> while
> Andrew> + being held in this map, as such completion_tracker must free
> these
> Andrew> + strings when finished with them, or pass ownership to
> someone else who
> Andrew> + will free them. */
> Andrew> + typedef std::unordered_map<const char *, const char *,
> std::hash<std::string>,
> Andrew> + std::equal_to<std::string>>
> completion_set;
>
> Does using std::string here mean that a temporary std::string will be
> made for each insertion in the map? And also for comparisons?
> That seems expensive if so.
>
Perhaps that's finally a use case to add hash<gdb::string_view>!
> Tom
>