diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 5661ec2eed8..757de639bc3 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -272,7 +272,10 @@ fn split_seps(data: &[u8], sep: u8) -> Vec<&[u8]> { // If data is empty (and does not even contain a single 'sep' // to indicate the presence of an empty element), then behave // as if the input contained no elements at all. - let mut elements: Vec<&[u8]> = data.split(|&b| b == sep).collect(); + const PREDICTED_LINE_LENGTH: usize = 64; + let predicted_capacity = data.len() / PREDICTED_LINE_LENGTH; + let mut elements = Vec::with_capacity(predicted_capacity); + elements.extend(data.split(|&b| b == sep)); if elements.last().is_some_and(|e| e.is_empty()) { elements.pop(); }