[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ba306b2a1b5743bab79b3ebb04ece4df@AcuMS.aculab.com>
Date: Tue, 16 Apr 2024 20:56:51 +0000
From: David Laight <David.Laight@...LAB.COM>
To: 'Al Viro' <viro@...iv.linux.org.uk>, Christophe JAILLET
<christophe.jaillet@...adoo.fr>
CC: Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"kernel-janitors@...r.kernel.org" <kernel-janitors@...r.kernel.org>,
"linux-fsdevel@...r.kernel.org" <linux-fsdevel@...r.kernel.org>
Subject: RE: [PATCH] seq_file: Optimize seq_puts()
From: Al Viro
> Sent: 15 April 2024 22:01
..
> No need to make it a macro, actually. And I would suggest going
> a bit further:
>
> static inline void seq_puts(struct seq_file *m, const char *s)
That probably needs to be 'always_inline'.
> {
> if (!__builtin_constant_p(*s))
> __seq_puts(m, s);
> else if (s[0] && !s[1])
> seq_putc(m, s[0]);
> else
> seq_write(m, s, __builtin_strlen(s));
> }
You missed seq_puts(m, "");
I did wonder about checking sizeof(s) <= 2 in the #define version.
That would pick up the cases where a separator is changed/added
in a loop.
Could you do:
size_t len = __builtin_strlen(s);
if (!__builtin_constant_p(len))
__seq_puts(m, s);
else switch (len){
case 0: break;
case 1: seq_putc(m, s[0]);
default: seq_write(m, s, len);
}
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists