Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some useless BufReader wrappers around stdin #1307

Merged
merged 2 commits into from
Feb 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Don’t wrap stdin in a BufReader when prompting
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.
  • Loading branch information
PaulCapron committed Oct 24, 2018
commit bb9cc77858e7d487d48a2fad80de138e2011f570
4 changes: 2 additions & 2 deletions src/cp/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/ln/ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/mv/mv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down