From: Philipp Rudo <prudo@linux.vnet.ibm.com>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org, peter.griffin@linaro.org,
yao.qi@arm.com, arnez@linux.vnet.ibm.com
Subject: Re: [RFC 2/7] Add libiberty/concat styled concat_path function
Date: Thu, 12 Jan 2017 13:33:00 -0000 [thread overview]
Message-ID: <20170112143315.338f6cfe@ThinkPad> (raw)
In-Reply-To: <f74f5182-7049-6f5b-822b-89a367f42db0@redhat.com>
Hi Pedro,
i see your point.
My goal here was to get rid of any C-string. While making this patch i
also wanted to use it to get rid of all those
concat (path, need_dirsep ? SLASH_STRING : "", NULL)
or
strcat (path, "/")
strcat (path, file)
constructs. I gave up when it repeatedly caused memory leaks and use
after free errors because of the mixture of C and C++ strings. Fixing
them made the code less readable than before. 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. Even when it costs performance.
Just my 0.02$
Philipp
On Thu, 12 Jan 2017 12:00:22 +0000
Pedro Alves <palves@redhat.com> wrote:
> On 01/12/2017 11:32 AM, Philipp Rudo wrote:
> > static inline int
> > -startswith (const char *string, const char *pattern)
> > +startswith (std::string str, std::string pattern)
>
> NAK.
>
> This is passing by copy, so will force unnecessary deep
> string copies all over the place.
>
> > {
> > - return strncmp (string, pattern, strlen (pattern)) == 0;
> > + return (str.find (pattern) == 0);
> > +}
> > +
>
> I.e., before, this caused 0 copies:
>
> startswith ("foo, "f");
>
> After, you force a deep string copy for "foo", and another
> for "f". It's as if you wrote:
>
> startswith (xstrdup ("foo), xstrdup ("f"));
>
>
> Also, this function is a static inline in a header so that
> the compiler can see when "pattern" is a string literal, and
> thus strlen can be optimized to a plain 'sizeof (pattern) - 1',
> which is very frequent.
>
> If you want to add overloads that can take "const std::string &"
> for convenience, to avoid str.c_str(), that's maybe fine,
> but you'd have to add all the combinations of
> 'const char *' x 'const std::string &' in the parameters, I
> suppose.
>
> Thanks,
> Pedro Alves
>
next prev parent reply other threads:[~2017-01-12 13:33 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-12 11:32 [RFC 0/7] Support for Linux kernel debugging Philipp Rudo
2017-01-12 11:32 ` [RFC 2/7] Add libiberty/concat styled concat_path function Philipp Rudo
2017-01-12 12:00 ` Pedro Alves
2017-01-12 13:33 ` Philipp Rudo [this message]
2017-01-12 13:48 ` Pedro Alves
2017-01-12 15:09 ` Philipp Rudo
2017-01-12 15:42 ` Pedro Alves
2017-01-12 11:32 ` [RFC 7/7] Add S390 support for linux-kernel target Philipp Rudo
2017-01-12 17:09 ` Luis Machado
2017-01-13 11:46 ` Philipp Rudo
2017-02-06 15:52 ` Yao Qi
2017-02-06 18:48 ` Andreas Arnez
2017-01-12 11:32 ` [RFC 6/7] Add privileged registers for s390x Philipp Rudo
2017-01-12 11:32 ` [RFC 3/7] Add basic Linux kernel support Philipp Rudo
2017-02-07 10:54 ` Yao Qi
2017-02-07 15:04 ` Philipp Rudo
2017-02-07 17:39 ` Yao Qi
2017-02-09 9:54 ` Philipp Rudo
2017-02-09 13:06 ` Yao Qi
2017-01-12 11:32 ` [RFC 1/7] Convert substitute_path_component to C++ Philipp Rudo
2017-01-12 11:32 ` [RFC 5/7] Add commands for linux-kernel target Philipp Rudo
2017-01-12 12:56 ` [RFC 0/7] Support for Linux kernel debugging Philipp Rudo
2017-01-12 13:02 ` [RFC 4/7] Add kernel module support for linux-kernel target Philipp Rudo
2017-01-25 18:10 ` [RFC 0/7] Support for Linux kernel debugging Peter Griffin
2017-01-26 13:12 ` Philipp Rudo
2017-02-03 17:45 ` Yao Qi
2017-02-03 19:46 ` Andreas Arnez
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=20170112143315.338f6cfe@ThinkPad \
--to=prudo@linux.vnet.ibm.com \
--cc=arnez@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=peter.griffin@linaro.org \
--cc=yao.qi@arm.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