Merge pull request #8869 from psvri/improve_hashsum

hashsum: improve hashsum using 32KiB bufreader - windows perfs
This commit is contained in:
Vrishabh 2025-10-21 00:27:47 +05:30 committed by GitHub
parent 8cc0cb8f10
commit d5bc7803e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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,