mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
shuf: Reduce malloc
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user