[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a109e614f82891ef6e99b0ab3535a90ccaf04181.camel@perches.com>
Date: Sat, 04 Sep 2021 18:36:41 -0700
From: Joe Perches <joe@...ches.com>
To: Yury Norov <yury.norov@...il.com>, Petr Mladek <pmladek@...e.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Andy Shevchenko <andy.shevchenko@...il.com>,
Bartosz Golaszewski <bgolaszewski@...libre.com>,
Chris Down <chris@...isdown.name>,
Gilles Muller <Gilles.Muller@...ia.fr>,
Ingo Molnar <mingo@...nel.org>,
Jacob Keller <jacob.e.keller@...el.com>,
Julia Lawall <Julia.Lawall@...ia.fr>,
Michal Marek <michal.lkml@...kovi.net>,
Nicolas Palix <nicolas.palix@...g.fr>,
Peter Zijlstra <peterz@...radead.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Sergey Senozhatsky <senozhatsky@...omium.org>,
Stephen Boyd <swboyd@...omium.org>,
Steven Rostedt <rostedt@...dmis.org>,
Thomas Gleixner <tglx@...utronix.de>,
linux-kernel@...r.kernel.org, cocci@...teme.lip6.fr
Subject: Re: [PATCH v2 1/2] lib: add sputchar() helper
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...
Powered by blists - more mailing lists