From: Tom Tromey <tromey@adacore.com>
To: Pedro Alves <palves@redhat.com>
Cc: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] Avoid copying in lookup_name_info
Date: Tue, 31 Mar 2020 13:11:21 -0600 [thread overview]
Message-ID: <87wo70baqu.fsf@tromey.com> (raw)
In-Reply-To: <e71db8b2-3a4d-b57f-119f-24dafa675c74@redhat.com> (Pedro Alves's message of "Tue, 31 Mar 2020 19:18:08 +0100")
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> I think it would be better for this overload to take a
Pedro> gdb::string_view instead of a const std::string& . That
Pedro> way, it still works if you only have a string_view handy.
Pedro> As is, there's no way to created a lookup_name_info starting
Pedro> with a string_view without copying. WDYT?
The issue is that there's a trick in the implementation:
/* Like the "name" method but guarantees that the returned string is
\0-terminated. */
const char *c_str () const
{
/* Actually this is always guaranteed due to how the class is
constructed. */
return m_name.data ();
}
This is needed in some spots.
However, if we take a string_view at construction, then we'd be
violating the string_view contract, or we'd need to make a copy -- but
the former is bad, and the latter is the goal the patch.
Pedro> And if we do that, do we have any case where we really need the
Pedro> "std::string &&" overload?
Indeed we don't seem to need this.
Tom
next prev parent reply other threads:[~2020-03-31 19:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-20 20:49 [PATCH 0/2] Avoid copying in name lookup Tom Tromey
2020-03-20 20:49 ` [PATCH 1/2] Avoid some copying in psymtab.c Tom Tromey
2020-03-31 17:46 ` Pedro Alves
2020-03-31 19:35 ` Tom Tromey
2020-03-20 20:49 ` [PATCH 2/2] Avoid copying in lookup_name_info Tom Tromey
2020-03-23 17:51 ` Christian Biesinger
2020-03-31 13:28 ` Tom Tromey
2020-03-31 18:18 ` Pedro Alves
2020-03-31 19:11 ` Tom Tromey [this message]
2020-03-31 19:15 ` Tom Tromey
2020-03-31 19:28 ` Pedro Alves
2020-03-31 19:35 ` Tom Tromey
2020-03-31 19:23 ` Pedro Alves
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=87wo70baqu.fsf@tromey.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.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