Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Philipp Rudo <prudo@linux.vnet.ibm.com>, gdb-patches@sourceware.org
Cc: Omair Javaid <omair.javaid@linaro.org>,
	Yao Qi <qiyaoltc@gmail.com>,
	arnez@linux.vnet.ibm.com
Subject: Re: [RFC PATCH v5 1/9] Convert substitute_path_component to C++
Date: Sat, 17 Mar 2018 20:11:00 -0000	[thread overview]
Message-ID: <bbc24ba9-e3a9-1b9d-fdde-8ad5e5f583e6@simark.ca> (raw)
In-Reply-To: <0e10fbb0-3138-301d-2e6b-747121544c71@simark.ca>

On 2018-03-15 10:15 PM, Simon Marchi wrote:
>> diff --git a/gdb/auto-load.c b/gdb/auto-load.c
>> index 70bddbc862..a7f9635252 100644
>> --- a/gdb/auto-load.c
>> +++ b/gdb/auto-load.c
>> @@ -175,21 +175,18 @@ std::vector<gdb::unique_xmalloc_ptr<char>> auto_load_safe_path_vec;
>>     substitute_path_component.  */
>>  
>>  static std::vector<gdb::unique_xmalloc_ptr<char>>
>> -auto_load_expand_dir_vars (const char *string)
>> +auto_load_expand_dir_vars (const std::string &string)
> 
> All the usages of auto_load_expand_dir_vars pass in a char pointer.  This means that
> a temporary std::string is created for the duration of the call (one copy) and another
> one is done lower.  I would suggest either to leave the parameter as const char * to
> avoid that copy.

I stumbled on the discussion you had with Pedro on the v1 patchset:

  https://sourceware.org/ml/gdb-patches/2017-01/msg00210.html

so I thought it would be good to expand a little bit.  A quote from that thread:

> Thus you should only use one kind of string through out GDB, either char * or
> std::string. And as GDB decided to move to C++ for me std::string is the way you
> should go.

I don't think we should be so dogmatic.  There are times where a "const char *" is
appropriate, others where std::string is appropriate.  A const std::string& is not
appropriate for a function that is potentially called with string literals, since it
will always require a copy.  As mentioned in that thread, backporting std::string_view
would be the way to go.  But until then, I think we should keep using const char *
in those cases.

Simon


  reply	other threads:[~2018-03-17 20:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-12 15:31 [RFC v5 0/9] Add support for Linux kernel debugging Philipp Rudo
2018-03-12 15:31 ` [RFC PATCH v5 7/9] Add privileged registers for s390x Philipp Rudo
2018-03-12 15:31 ` [RFC PATCH v5 5/9] Add kernel module support for linux-kernel target Philipp Rudo
2018-03-12 15:31 ` [RFC PATCH v5 2/9] Add libiberty/concat styled concat_path function Philipp Rudo
2018-03-16  2:47   ` Simon Marchi
2018-03-12 15:31 ` [RFC PATCH v5 9/9] Add S390 support for linux-kernel target Philipp Rudo
2018-03-12 15:31 ` [RFC PATCH v5 3/9] Add scoped_restore_regcache_ptid Philipp Rudo
2018-03-17 18:08   ` Simon Marchi
2018-03-12 15:31 ` [RFC PATCH v5 4/9] Add basic Linux kernel support Philipp Rudo
2018-03-13 14:09   ` Kamil Rytarowski
2018-03-14  9:48     ` Philipp Rudo
2018-03-14 23:38       ` Kamil Rytarowski
2018-03-19  0:11   ` Simon Marchi
2018-03-12 15:31 ` [RFC PATCH v5 6/9] Add commands for linux-kernel target Philipp Rudo
2018-03-12 15:31 ` [RFC PATCH v5 1/9] Convert substitute_path_component to C++ Philipp Rudo
2018-03-16  2:15   ` Simon Marchi
2018-03-17 20:11     ` Simon Marchi [this message]
2018-03-12 15:31 ` [RFC PATCH v5 8/9] Link frame_info to thread_info Philipp Rudo

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=bbc24ba9-e3a9-1b9d-fdde-8ad5e5f583e6@simark.ca \
    --to=simark@simark.ca \
    --cc=arnez@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=omair.javaid@linaro.org \
    --cc=prudo@linux.vnet.ibm.com \
    --cc=qiyaoltc@gmail.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