All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: Joe Perches <joe@perches.com>
Cc: Petr Mladek <pmladek@suse.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Chris Down <chris@chrisdown.name>,
	Gilles Muller <Gilles.Muller@inria.fr>,
	Ingo Molnar <mingo@kernel.org>,
	Jacob Keller <jacob.e.keller@intel.com>,
	Julia Lawall <Julia.Lawall@inria.fr>,
	Michal Marek <michal.lkml@markovi.net>,
	Nicolas Palix <nicolas.palix@imag.fr>,
	Peter Zijlstra <peterz@infradead.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Sergey Senozhatsky <senozhatsky@chromium.org>,
	Stephen Boyd <swboyd@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr
Subject: Re: [PATCH v2 1/2] lib: add sputchar() helper
Date: Sat, 4 Sep 2021 20:20:21 -0700	[thread overview]
Message-ID: <YTQ3dQSmougYRDA9@yury-ThinkPad> (raw)
In-Reply-To: <a109e614f82891ef6e99b0ab3535a90ccaf04181.camel@perches.com>

On Sat, Sep 04, 2021 at 06:36:41PM -0700, Joe Perches wrote:
> On Sat, 2021-09-04 at 16:10 -0700, Yury Norov wrote:
> > There are 47 occurrences of the code snippet like this:
> > 	if (buf < end)
> > 	        *buf = ' ';
> > 	++buf;
> > 
> > This patch adds a helper function sputchar() to replace opencoding.
> > It adds a lot to readability, and also saves 43 bytes of text on x86.
> 
> I think this patch does little to improve readability.
> 
> Perhaps make it void and use something like
> 
> 	sputchar(*buf++, end, <whateverchar>);

It's better, thank you.
 
> Though the sputchar name doesn't seems particularly intelligible.

I'm OK with any better name.

Thanks,
Yury

> > +static inline char *sputchar(char *buf, const char *end, char c)
> > +{
> > +	if (buf < end)
> > +		*buf = c;
> > +
> > +	return buf + 1;
> > +}
> > +
> >  /*
> >   * General tracing related utility functions - trace_printk(),
> >   * tracing_on/tracing_off and tracing_start()/tracing_stop
> > diff --git a/lib/string_helpers.c b/lib/string_helpers.c
> []
> > @@ -335,12 +335,8 @@ static bool escape_space(unsigned char c, char **dst, char *end)
> >  		return false;
> >  	}
> > 
> > -	if (out < end)
> > -		*out = '\\';
> > -	++out;
> > -	if (out < end)
> > -		*out = to;
> > -	++out;
> > +	out = sputchar(out, end, '\\');
> > +	out = sputchar(out, end, to);
> 
> etc...
> 

  reply	other threads:[~2021-09-05  3:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04 23:10 [PATCH 0/2] lib: add sputchar() helper Yury Norov
2021-09-04 23:10 ` [PATCH v2 1/2] " Yury Norov
2021-09-05  1:36   ` Joe Perches
2021-09-05  3:20     ` Yury Norov [this message]
2021-09-06 11:51   ` Rasmus Villemoes
2021-09-07  9:35     ` Petr Mladek
2021-09-04 23:10 ` [PATCH 2/2] coccinelle: add script for sputchar() Yury Norov

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=YTQ3dQSmougYRDA9@yury-ThinkPad \
    --to=yury.norov@gmail.com \
    --cc=Gilles.Muller@inria.fr \
    --cc=Julia.Lawall@inria.fr \
    --cc=akpm@linux-foundation.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=chris@chrisdown.name \
    --cc=cocci@systeme.lip6.fr \
    --cc=jacob.e.keller@intel.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=michal.lkml@markovi.net \
    --cc=mingo@kernel.org \
    --cc=nicolas.palix@imag.fr \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    --cc=swboyd@chromium.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.