From: Joe Perches <joe@perches.com>
To: Yury Norov <yury.norov@gmail.com>, 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, 04 Sep 2021 18:36:41 -0700 [thread overview]
Message-ID: <a109e614f82891ef6e99b0ab3535a90ccaf04181.camel@perches.com> (raw)
In-Reply-To: <20210904231020.331185-2-yury.norov@gmail.com>
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>);
Though the sputchar name doesn't seems particularly intelligible.
> +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...
next prev parent reply other threads:[~2021-09-05 2:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-04 23:10 [PATCH 0/2] " Yury Norov
2021-09-04 23:10 ` [PATCH v2 1/2] " Yury Norov
2021-09-05 1:36 ` Joe Perches [this message]
2021-09-05 3:20 ` Yury Norov
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=a109e614f82891ef6e99b0ab3535a90ccaf04181.camel@perches.com \
--to=joe@perches.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=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 \
--cc=yury.norov@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
all inboxes | Powered by JetHome®