From fe871164314736642dc923c12e92c2e902160caf Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 21 Oct 2017 21:23:06 +0200 Subject: [PATCH] Make 'yes' 1000 times faster. --- src/yes/yes.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/yes/yes.rs b/src/yes/yes.rs index 49643c732..c79ea6340 100644 --- a/src/yes/yes.rs +++ b/src/yes/yes.rs @@ -22,6 +22,8 @@ use std::io::Write; static NAME: &'static str = "yes"; static VERSION: &'static str = env!("CARGO_PKG_VERSION"); +const BUF_SIZE: usize = 8192; + pub fn uumain(args: Vec) -> i32 { let mut opts = Options::new(); @@ -51,7 +53,13 @@ pub fn uumain(args: Vec) -> i32 { matches.free.join(" ") }; - exec(&string[..]); + let mut multistring = string.clone(); + while multistring.len() < BUF_SIZE - string.len() - 1 { + multistring.push_str("\n"); + multistring.push_str(&string); + } + + exec(&multistring[..]); 0 }