]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: make output redirection more efficient
authorSami Kerola <kerolasa@iki.fi>
Sat, 3 Aug 2013 23:15:20 +0000 (00:15 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 5 Aug 2013 08:47:47 +0000 (10:47 +0200)
Especially with large inputs the change improves performance
considerably.

old> time more /boot/vmlinuz >/dev/null
real    0m0.224s

new> more /boot/vmlinuz >/dev/null
real    0m0.009s

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/more.c

index ac35acc0bd16250fb4929354bbc3324a42b124e3..598e048963a3c47577ff693a89774ef530fe3281 100644 (file)
@@ -780,10 +780,11 @@ void __attribute__((__noreturn__)) end_it(int dummy __attribute__((__unused__)))
 
 void copy_file(register FILE *f)
 {
-       register int c;
+       char buf[BUFSIZ];
+       size_t sz;
 
-       while ((c = getc(f)) != EOF)
-               putchar(c);
+       while ((sz = fread(&buf, sizeof(char), sizeof(buf), f)) > 0)
+               fwrite(&buf, sizeof(char), sz, stdout);
 }
 
 #define ringbell()     putcerr('\007')