Re: [PATCH] seq_file: Optimize seq_puts()

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

 



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...




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux