From 9326dbc3de7fde53db5b34bec3dfbc825c45ee7c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sat, 24 Jan 2015 22:52:40 -0500 Subject: [PATCH] Cleanup cat: open files in for loop header. --- src/cat/cat.rs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/cat/cat.rs b/src/cat/cat.rs index 9e6f179f1..1d8011f74 100644 --- a/src/cat/cat.rs +++ b/src/cat/cat.rs @@ -95,11 +95,7 @@ fn write_lines(files: Vec, number: NumberingMode, squeeze_blank: bool, let mut line_counter: usize = 1; - for path in files.iter() { - let (mut reader, interactive) = match open(path.as_slice()) { - Some(f) => f, - None => continue, - }; + for (mut reader, interactive) in files.iter().filter_map(|p| open(&p[])) { let mut in_buf = [0; 1024 * 31]; let mut out_buf = [0; 1024 * 64]; @@ -168,11 +164,7 @@ fn write_bytes(files: Vec, number: NumberingMode, squeeze_blank: bool, let mut line_counter: usize = 1; - for path in files.iter() { - let (mut reader, interactive) = match open(path.as_slice()) { - Some(f) => f, - None => continue, - }; + for (mut reader, interactive) in files.iter().filter_map(|p| open(&p[])) { // Flush all 1024 iterations. let mut flush_counter = range(0us, 1024); @@ -246,12 +238,7 @@ fn write_fast(files: Vec) { let mut writer = stdout_raw(); let mut in_buf = [0; 1024 * 64]; - for path in files.iter() { - let (mut reader, _) = match open(path.as_slice()) { - Some(x) => x, - None => continue, - }; - + for (mut reader, _) in files.iter().filter_map(|p| open(&p[])) { loop { match reader.read(&mut in_buf) { Ok(n) if n != 0 => {