From: Sami Kerola Date: Sat, 3 Aug 2013 23:15:20 +0000 (+0100) Subject: more: make output redirection more efficient X-Git-Tag: v2.24-rc1~404 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2587c5937c506eb399e2012141c6d6b7d381552b;p=thirdparty%2Futil-linux.git more: make output redirection more efficient 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 --- diff --git a/text-utils/more.c b/text-utils/more.c index ac35acc0bd..598e048963 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -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')