From bb1ede3fa4f9c00fdb3f809356dcf6465781f74d Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sat, 7 Mar 2026 01:18:27 +0900 Subject: [PATCH] shuf: Reduce malloc --- src/uu/shuf/src/shuf.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 5661ec2ee..757de639b 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(); }