From a42bdea8ac37c8c8c739015da4f55d4468a6e9a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Wed, 19 Mar 2014 09:42:34 -0700 Subject: [PATCH] Use Buffered input/output where it makes sense. (cherry picked from commit c084bb1568d62d0e3e17151c8a4e859a95805a07) --- cat/cat.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cat/cat.rs b/cat/cat.rs index 9c806d9b1..1cb42c35d 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -17,6 +17,7 @@ extern crate getopts; use std::os; use std::io::{print, File}; use std::io::stdio::{stdout_raw, stdin_raw}; +use std::io::{BufferedReader, BufferedWriter}; fn main() { let args = os::args(); @@ -96,7 +97,6 @@ fn is_newline_char(byte: u8) -> bool { } pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_ends: bool, show_tabs: bool, squeeze_blank: bool) { - let mut writer = stdout_raw(); if NumberNone != number || show_nonprint || show_ends || show_tabs || squeeze_blank { let mut counter: uint = 1; @@ -108,6 +108,7 @@ pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_end None => { continue } }; + let mut writer = BufferedWriter::with_capacity(1024 * 8, stdout_raw()); let mut at_line_start = true; let mut buf = [0, .. 2]; loop { @@ -170,6 +171,7 @@ pub fn exec(files: ~[~str], number: NumberingMode, show_nonprint: bool, show_end } let mut buf = [0, .. 100000]; + let mut writer = stdout_raw(); // passthru mode for path in files.iter() { let mut reader = match open(path.to_owned()) {