[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240417010430.GB2118490@ZenIV>
Date: Wed, 17 Apr 2024 02:04:30 +0100
From: Al Viro <viro@...iv.linux.org.uk>
To: David Laight <David.Laight@...lab.com>
Cc: Christophe JAILLET <christophe.jaillet@...adoo.fr>,
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()
On Tue, Apr 16, 2024 at 08:56:51PM +0000, David Laight wrote:
> > static inline void seq_puts(struct seq_file *m, const char *s)
>
> That probably needs to be 'always_inline'.
What for? If compiler fails to inline it (and I'd be very surprised
if that happened - if s is not a constant string, we get a straight call
of __seq_puts() and for constant strings it boils down to call of
seq_putc(m, constant) or seq_write(m, s, constant)), nothing bad
would happen; we'd still get correct behaviour.
> > {
> > 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, "");
Where have you seen one? And if it gets less than optimal, who cares?
> 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);
> }
Umm... That's probably OK, but I wonder how useful would that
be...
Powered by blists - more mailing lists