1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

sort: improve memory usage for extsort

This commit is contained in:
Michael Debertol 2021-05-07 21:50:33 +02:00
parent c38373946a
commit 8c9faa16b9

View file

@ -113,7 +113,7 @@ pub fn ext_sort(
chunk.push(seq);
if total_read >= settings.buffer_size {
if total_read + chunk.len() * std::mem::size_of::<Line>() >= settings.buffer_size {
super::sort_by(&mut chunk, &settings);
write_chunk(
settings,
@ -136,6 +136,9 @@ pub fn ext_sort(
iter.chunks += 1;
}
// We manually drop here to not go over our memory limit when we allocate below.
drop(chunk);
// initialize buffers for each chunk
//
// Having a right sized buffer for each chunk for smallish values seems silly to me?