Re: [PATCH v2 1/2] lib: add sputchar() helper
From: Rasmus Villemoes
Date: Mon Sep 06 2021 - 07:52:10 EST
On 05/09/2021 01.10, 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.
>
> v2: cleanup cases discovered with coccinelle script.
>
> Signed-off-by: Yury Norov <yury.norov@xxxxxxxxx>
> ---
> include/linux/kernel.h | 8 ++
Sorry, but 47 cases, mostly in one .c file, is not enough justification
for adding yet another piece of random code to
the-dumping-ground-which-is-kernel.h, especially since this helper is
very specific to the needs of the vsnprintf() implementation, so
extremely unlikely to find other users.
I'm also not a fan of the sputchar name - it's unreadable at first
glance, and when you figure out it's "a _s_tring version of putchar",
that doesn't help, because its semantics are nothing like the stdio putchar.
Rasmus