RE: [PATCH] seq_file: Optimize seq_puts()

From: David Laight
Date: Sun Apr 21 2024 - 13:22:33 EST


From: Christophe JAILLET
> Sent: 19 April 2024 21:38
...
> > I did wonder about checking sizeof(s) <= 2 in the #define version.
>
> git grep seq_puts.*\"[^\\].\" | wc -l
> 77
>
> What would you do in this case?
> 2 seq_putc() in order to save a memcpy(..., 2), that's it?
>
> It would also slightly change the behaviour, as only the 1st char could
> be added. Actually, it is all or nothing.

Doing:
if (sizeof(str) == 2 && str[0])
seq_putc(m. str[0]);
else
__seq_puts(m, str);
Would pick up loops that do:
char sep[2] = "";

for (;; sep[0] = ',') {
...
seq_puts(m, sep);
...
}
as well as seq_puts(m, "x");

Whether that is worthwhile is another matter.
But it might be used.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)