Re: [PATCH] seq_file: Optimize seq_puts()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le 17/04/2024 à 03:04, Al Viro a écrit :
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?

Based on results from:
   git grep seq_puts.*\"\"

there is no such cases.


 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]);

missing break;

	default: seq_write(m, s, len);
	}

Umm...  That's probably OK, but I wonder how useful would that
be...


Thanks all for your feedback.

I'll send a v2.

CJ







[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux