diff options
author | Sami Kerola | 2013-08-04 01:15:20 +0200 |
---|---|---|
committer | Karel Zak | 2013-08-05 10:47:47 +0200 |
commit | 2587c5937c506eb399e2012141c6d6b7d381552b (patch) | |
tree | d9aa097795f224be9a9bd49399238585ea7a304b /text-utils/more.c | |
parent | column: use variable lenght printf field width to wprint blanks (diff) | |
download | kernel-qcow2-util-linux-2587c5937c506eb399e2012141c6d6b7d381552b.tar.gz kernel-qcow2-util-linux-2587c5937c506eb399e2012141c6d6b7d381552b.tar.xz kernel-qcow2-util-linux-2587c5937c506eb399e2012141c6d6b7d381552b.zip |
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 <kerolasa@iki.fi>
Diffstat (limited to 'text-utils/more.c')
-rw-r--r-- | text-utils/more.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/text-utils/more.c b/text-utils/more.c index ac35acc0b..598e04896 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') |