On Tue, 2018-08-28 at 11:24 -0700, Joe Perches wrote:
> On Tue, 2018-08-28 at 02:14 +0300, Alexey Dobriyan wrote:
> > Space savings -- 42 bytes!
> > 
> >     seq_puts        71      29     [-42]
> > 
> > Signed-off-by: Alexey Dobriyan <adobri...@gmail.com>
> > ---
> >  fs/seq_file.c | 9 +--------
> >  1 file changed, 1 insertion(+), 8 deletions(-)
> > 
> > diff --git a/fs/seq_file.c b/fs/seq_file.c
> > index 1dea7a8a5255..0c282a88a896 100644
> > --- a/fs/seq_file.c
> > +++ b/fs/seq_file.c
> > @@ -653,14 +653,7 @@ EXPORT_SYMBOL(seq_putc);
> >  
> >  void seq_puts(struct seq_file *m, const char *s)
> >  {
> > -   int len = strlen(s);
> > -
> > -   if (m->count + len >= m->size) {
> > -           seq_set_overflow(m);
> > -           return;
> > -   }
> > -   memcpy(m->buf + m->count, s, len);
> > -   m->count += len;
> > +   seq_write(m, s, strlen(s));
> >  }
> >  EXPORT_SYMBOL(seq_puts);
> >  
> 
> If execution speed is really an issue, as
> almost all of the uses are for const strings,
> why not use a #define and avoid the runtime
> cost of strlen where possible.

fyi: an x86-64 defconfig increases < .5 kb and
presumably is faster for most all seq_puts uses

$ size vmlinux.new vmlinux.old
   text    data     bss     dec     hex 
filename
17342316        4982128  999628 23324072        163e5a8 
vmlinux.new
17341857        4982128  999628 23323613        163e3dd 
vmlinux.old

with
---
 fs/seq_file.c            | 13 -------------
 include/linux/seq_file.h |  2 +-
 2 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/fs/seq_file.c b/fs/seq_file.c
index 1dea7a8a5255..97d474b6788e 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -651,19 +651,6 @@ void seq_putc(struct seq_file *m, char c)
 }
 EXPORT_SYMBOL(seq_putc);
 
-void seq_puts(struct seq_file *m, const char *s)
-{
-       int len = strlen(s);
-
-       if (m->count + len >= m->size) {
-               seq_set_overflow(m);
-               return;
-       }
-       memcpy(m->buf + m->count, s, len);
-       m->count += len;
-}
-EXPORT_SYMBOL(seq_puts);
-
 /**
  * A helper routine for putting decimal numbers without rich format of 
printf().
  * only 'unsigned long long' is supported.
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index a121982af0f5..722028805df6 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -117,7 +117,7 @@ void seq_vprintf(struct seq_file *m, const char *fmt, 
va_list args);
 __printf(2, 3)
 void seq_printf(struct seq_file *m, const char *fmt, ...);
 void seq_putc(struct seq_file *m, char c);
-void seq_puts(struct seq_file *m, const char *s);
+#define seq_puts(m, s) seq_write(m, s, strlen(s))
 void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter,
                               unsigned long long num, unsigned int width);
 void seq_put_decimal_ull(struct seq_file *m, const char *delimiter,

Reply via email to