From: Namhyung Kim <namhyung@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Joe Perches <joe@perches.com>,
LKML <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Tom Zanussi <zanussi@kernel.org>,
kernel-team@lge.com
Subject: Re: [PATCH v3] string.h: Add str_has_prefix() helper
Date: Sun, 23 Dec 2018 12:23:28 +0900 [thread overview]
Message-ID: <20181223032328.GC11421@danjae.aot.lge.com> (raw)
In-Reply-To: <20181222072207.1fe78930@vmware.local.home>
On Sat, Dec 22, 2018 at 07:22:07AM -0500, Steven Rostedt wrote:
> On Sat, 22 Dec 2018 18:28:18 +0900
> Namhyung Kim <namhyung@kernel.org> wrote:
>
> > >
> > > for (i = 0; i < hist_data->attrs->n_actions; i++) {
> > > str = hist_data->attrs->action_str[i];
> > >
> > > - if (str_has_prefix(str, "onmatch(")) {
> > > - char *action_str = str + sizeof("onmatch(") - 1;
> > > + if ((len = str_has_prefix(str, "onmatch("))) {
> > > + char *action_str = str + len;
> >
> > IMHO, returning (match) length might confuse people that it might
> > support partial match and returns the length actually matched rather
> > than full match. If I knew it always returns the length of prefix (or
> > 0) why it matters? Using strlen() in the next line will have same
> > effect of compiler optimization for the constant strings, no?
> >
> > if (str_has_prefix(str, "onmatch(")) {
> > char *action_str = str + strlen("onmatch(");
>
> The reason to return the length was to get rid of the need for
> duplicating the strlen("xxxx") because it's a burden to keep the two
> the same. Not only that, a lot of places just do "str + 7" because it's
> easier to type.
>
> Yes, it has the same effect on the compiler, but that's not what we are
> trying to solve. We are trying to get rid of the duplication, because
> that requires humans to get it right, and humans are not good at that.
Then I'm ok with that. :)
Thanks,
Namhyung
next prev parent reply other threads:[~2018-12-23 3:23 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-21 23:13 Steven Rostedt
2018-12-21 23:19 ` Joe Perches
2018-12-21 23:25 ` Steven Rostedt
2018-12-21 23:38 ` Steven Rostedt
2018-12-22 9:28 ` Namhyung Kim
2018-12-22 12:22 ` Steven Rostedt
2018-12-23 3:23 ` Namhyung Kim [this message]
2018-12-21 23:44 ` Joe Perches
2018-12-22 0:00 ` Steven Rostedt
2018-12-22 0:06 ` Steven Rostedt
2018-12-22 0:22 ` Joe Perches
[not found] ` <CAHk-=wgfSR9qhEWf--Do11jUFHyVM+VEmwm5LBS2JsV0F5yakw@mail.gmail.com>
2018-12-22 0:37 ` Steven Rostedt
2018-12-22 10:58 ` Ingo Molnar
2018-12-22 13:16 ` Steven Rostedt
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=20181223032328.GC11421@danjae.aot.lge.com \
--to=namhyung@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=joe@perches.com \
--cc=kernel-team@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
--cc=zanussi@kernel.org \
/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
all inboxes | Powered by JetHome®