diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 7bd67276bf3..89e771c4796 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -28,8 +28,9 @@ pub const BASE_CMD_PARSE_ERROR: i32 = 1; /// /// This default is only used if no "-w"/"--wrap" argument is passed pub const WRAP_DEFAULT: usize = 76; -// Fixed to 8 KiB (equivalent to std::io::DEFAULT_BUF_SIZE on most targets) -pub const DEFAULT_BUFFER_SIZE: usize = 8 * 1024; + +// Fixed to 8 KiB (equivalent to `std::sys::io::DEFAULT_BUF_SIZE` on most targets) +pub const DEFAULT_BUF_SIZE: usize = 8 * 1024; pub struct Config { pub decode: bool, @@ -151,15 +152,12 @@ pub fn get_input(config: &Config) -> UResult> { Some(path_buf) => { let file = File::open(path_buf).map_err_context(|| path_buf.maybe_quote().to_string())?; - Ok(Box::new(BufReader::with_capacity( - DEFAULT_BUFFER_SIZE, - file, - ))) + Ok(Box::new(BufReader::with_capacity(DEFAULT_BUF_SIZE, file))) } None => { // Stdin is already buffered by the OS; wrap once more to reduce syscalls per read. Ok(Box::new(BufReader::with_capacity( - DEFAULT_BUFFER_SIZE, + DEFAULT_BUF_SIZE, io::stdin(), ))) } diff --git a/src/uu/sort/benches/sort_bench.rs b/src/uu/sort/benches/sort_bench.rs index 61e5f4564bb..08a23b65602 100644 --- a/src/uu/sort/benches/sort_bench.rs +++ b/src/uu/sort/benches/sort_bench.rs @@ -214,7 +214,7 @@ fn sort_unique_locale(bencher: Bencher, num_lines: usize) { }); } -/// Benchmark sorting with very long lines exceeding START_BUFFER_SIZE (8000 bytes) +/// Benchmark sorting with very long lines exceeding `DEFAULT_BUF_SIZE` (8192 bytes) #[divan::bench(args = [10_000])] fn sort_long_line(bencher: Bencher, line_size: usize) { // Create files with very long lines to test buffer handling diff --git a/src/uu/sort/src/ext_sort.rs b/src/uu/sort/src/ext_sort.rs index 74a6e1fd7eb..e1cd8bf01c6 100644 --- a/src/uu/sort/src/ext_sort.rs +++ b/src/uu/sort/src/ext_sort.rs @@ -36,7 +36,8 @@ use crate::{ use crate::{Line, print_sorted}; // Note: update `test_sort::test_start_buffer` if this size is changed -const START_BUFFER_SIZE: usize = 8_000; +// Fixed to 8 KiB (equivalent to `std::sys::io::DEFAULT_BUF_SIZE` on most targets) +const DEFAULT_BUF_SIZE: usize = 8 * 1024; /// Sort files by using auxiliary files for storing intermediate chunks (if needed), and output the result. pub fn ext_sort( @@ -224,11 +225,7 @@ fn read_write_loop( for _ in 0..2 { let should_continue = chunks::read( &sender, - RecycledChunk::new(if START_BUFFER_SIZE < buffer_size { - START_BUFFER_SIZE - } else { - buffer_size - }), + RecycledChunk::new(buffer_size.min(DEFAULT_BUF_SIZE)), Some(buffer_size), &mut carry_over, &mut file,