Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: 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 19:18:08 +0100	[thread overview]
Message-ID: <e71db8b2-3a4d-b57f-119f-24dafa675c74@redhat.com> (raw)
In-Reply-To: <20200320204935.19509-3-tromey@adacore.com>

On 3/20/20 8:49 PM, Tom Tromey wrote:

>    return lookup_name;
> diff --git a/gdb/symtab.h b/gdb/symtab.h
> index 771b5ec5bf7..c80acc3a68e 100644
> --- a/gdb/symtab.h
> +++ b/gdb/symtab.h
> @@ -186,28 +186,62 @@ class lookup_name_info final
>  {
>   public:
>    /* Create a new object.  */
> -  lookup_name_info (std::string name,
> +  lookup_name_info (std::string &&name,
>  		    symbol_name_match_type match_type,
>  		    bool completion_mode = false,
>  		    bool ignore_parameters = false)
>      : m_match_type (match_type),
>        m_completion_mode (completion_mode),
>        m_ignore_parameters (ignore_parameters),
> -      m_name (std::move (name))
> +      m_name_holder (std::move (name)),
> +      m_name (m_name_holder.c_str ())
> +  {}
> +
> +  /* This overload requires that NAME have a lifetime at least as long
> +     as the lifetime of this object.  */
> +  lookup_name_info (const std::string &name,

I think it would be better for this overload to take a
gdb::string_view instead of a const std::string& .  That
way, it still works if you only have a string_view handy.
As is, there's no way to created a lookup_name_info starting
with a string_view without copying.  WDYT?

And if we do that, do we have any case where we really need the
"std::string &&" overload?  You mention that normally copying
isn't needed -- but when is copying needed?  I.e., do we have
cases where the lookup_name_info object doesn't have a lifetime greater
than the original string?  If there isn't, then we could also get
rid of name_holder, and avoid having to remember that different
ctors behave differently.

Thanks,
Pedro Alves



  parent reply	other threads:[~2020-03-31 18:18 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 [this message]
2020-03-31 19:11     ` Tom Tromey
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=e71db8b2-3a4d-b57f-119f-24dafa675c74@redhat.com \
    --to=palves@redhat.com \
    --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