mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
Merge pull request #8869 from psvri/improve_hashsum
hashsum: improve hashsum using 32KiB bufreader - windows perfs
This commit is contained in:
parent
8cc0cb8f10
commit
d5bc7803e4
1 changed files with 22 additions and 17 deletions
|
|
@ -31,6 +31,8 @@ use uucore::sum::{Digest, Sha3_224, Sha3_256, Sha3_384, Sha3_512, Shake128, Shak
|
|||
use uucore::translate;
|
||||
|
||||
const NAME: &str = "hashsum";
|
||||
// Using the same read buffer size as GNU
|
||||
const READ_BUFFER_SIZE: usize = 32 * 1024;
|
||||
|
||||
struct Options<'a> {
|
||||
algoname: &'static str,
|
||||
|
|
@ -541,23 +543,26 @@ where
|
|||
for filename in files {
|
||||
let filename = Path::new(filename);
|
||||
|
||||
let mut file = BufReader::new(if filename == OsStr::new("-") {
|
||||
Box::new(stdin()) as Box<dyn Read>
|
||||
} else {
|
||||
let file_buf = match File::open(filename) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"{}: {}: {e}",
|
||||
options.binary_name,
|
||||
filename.to_string_lossy()
|
||||
);
|
||||
err_found = Some(ChecksumError::Io(e));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
Box::new(file_buf) as Box<dyn Read>
|
||||
});
|
||||
let mut file = BufReader::with_capacity(
|
||||
READ_BUFFER_SIZE,
|
||||
if filename == OsStr::new("-") {
|
||||
Box::new(stdin()) as Box<dyn Read>
|
||||
} else {
|
||||
let file_buf = match File::open(filename) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"{}: {}: {e}",
|
||||
options.binary_name,
|
||||
filename.to_string_lossy()
|
||||
);
|
||||
err_found = Some(ChecksumError::Io(e));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
Box::new(file_buf) as Box<dyn Read>
|
||||
},
|
||||
);
|
||||
|
||||
let (sum, _) = digest_reader(
|
||||
&mut options.digest,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue