From bb9cc77858e7d487d48a2fad80de138e2011f570 Mon Sep 17 00:00:00 2001 From: Paul Capron Date: Wed, 24 Oct 2018 15:08:51 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20wrap=20stdin=20in=20a=20BufRead?= =?UTF-8?q?er=20when=20prompting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stdin() is already buffered. stdin().read_line() calls stdin().lock() behind the hood (see https://doc.rust-lang.org/src/std/io/stdio.rs.html#274) Here we are reading user input, prompting them to confirm their action: it seems useless to handle mutex locking/unlocking explicitely and beforehand to avoid its overhead. This commit is related to issue #1103. --- src/cp/cp.rs | 4 ++-- src/ln/ln.rs | 4 ++-- src/mv/mv.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index de05619c4..ae04475b1 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -42,7 +42,7 @@ use clap::{App, Arg, ArgMatches}; use quick_error::ResultExt; use std::collections::HashSet; use std::fs; -use std::io::{stdin, stdout, BufRead, BufReader, Write}; +use std::io::{stdin, stdout, Write}; use std::io; use std::path::{Path, PathBuf, StripPrefixError}; use std::str::FromStr; @@ -123,7 +123,7 @@ macro_rules! prompt_yes( print!(" [y/N]: "); crash_if_err!(1, stdout().flush()); let mut s = String::new(); - match BufReader::new(stdin()).read_line(&mut s) { + match stdin().read_line(&mut s) { Ok(_) => match s.char_indices().nth(0) { Some((_, x)) => x == 'y' || x == 'Y', _ => false diff --git a/src/ln/ln.rs b/src/ln/ln.rs index d182bd688..d6c89f50d 100644 --- a/src/ln/ln.rs +++ b/src/ln/ln.rs @@ -13,7 +13,7 @@ extern crate uucore; use std::fs; -use std::io::{stdin, BufRead, BufReader, Result}; +use std::io::{stdin, Result}; #[cfg(any(unix, target_os = "redox"))] use std::os::unix::fs::symlink; #[cfg(windows)] @@ -303,7 +303,7 @@ fn link(src: &PathBuf, dst: &PathBuf, settings: &Settings) -> Result<()> { fn read_yes() -> bool { let mut s = String::new(); - match BufReader::new(stdin()).read_line(&mut s) { + match stdin().read_line(&mut s) { Ok(_) => match s.char_indices().nth(0) { Some((_, x)) => x == 'y' || x == 'Y', _ => false, diff --git a/src/mv/mv.rs b/src/mv/mv.rs index 1b1ee68db..19746c956 100644 --- a/src/mv/mv.rs +++ b/src/mv/mv.rs @@ -16,7 +16,7 @@ extern crate uucore; use std::fs; use std::env; -use std::io::{stdin, BufRead, BufReader, Result}; +use std::io::{stdin, Result}; use std::path::{Path, PathBuf}; static NAME: &str = "mv"; @@ -374,7 +374,7 @@ fn rename(from: &PathBuf, to: &PathBuf, b: &Behaviour) -> Result<()> { fn read_yes() -> bool { let mut s = String::new(); - match BufReader::new(stdin()).read_line(&mut s) { + match stdin().read_line(&mut s) { Ok(_) => match s.chars().nth(0) { Some(x) => x == 'y' || x == 'Y', _ => false,