shuf: Reduce malloc

This commit is contained in:
oech3
2026-03-07 01:26:30 +09:00
parent 54cfd30196
commit bb1ede3fa4
+4 -1
View File
@@ -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();
}