lkml.org 
[lkml]   [2024]   [Apr]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [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...

\
 
 \ /
  Last update: 2024-04-17 03:04    [W:0.103 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site