Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 5 additions & 7 deletions src/uu/base32/src/base_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -151,15 +152,12 @@ pub fn get_input(config: &Config) -> UResult<Box<dyn BufRead>> {
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(),
)))
}
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sort/benches/sort_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/uu/sort/src/ext_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -224,11 +225,7 @@ fn read_write_loop<I: WriteableTmpFile>(
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,
Expand Down
Loading