split: Reduce malloc

This commit is contained in:
oech3
2026-02-16 23:48:11 +09:00
committed by Daniel Hofstetter
parent 1340183cba
commit f0c71b2477
+4 -4
View File
@@ -1156,7 +1156,7 @@ where
out_files = OutFiles::init(num_chunks, settings, false)?;
}
let buf = &mut Vec::new();
let mut buf = Vec::with_capacity((chunk_size_base + 1) as usize);
for i in 1_u64..=num_chunks {
let chunk_size = chunk_size_base + (chunk_size_reminder > i - 1) as u64;
buf.clear();
@@ -1175,7 +1175,7 @@ where
}
};
let n_bytes_read = reader.by_ref().take(limit).read_to_end(buf);
let n_bytes_read = reader.by_ref().take(limit).read_to_end(&mut buf);
match n_bytes_read {
Ok(n_bytes) => {
@@ -1191,13 +1191,13 @@ where
if let Some(chunk_number) = kth_chunk {
if i == chunk_number {
stdout_writer.write_all(buf)?;
stdout_writer.write_all(&buf)?;
break;
}
} else {
let idx = (i - 1) as usize;
let writer = out_files.get_writer(idx, settings)?;
writer.write_all(buf)?;
writer.write_all(&buf)?;
}
} else {
break;