diff --git a/src/compute/sort/boolean.rs b/src/compute/sort/boolean.rs index bb7faec6efa..6afdd551ec1 100644 --- a/src/compute/sort/boolean.rs +++ b/src/compute/sort/boolean.rs @@ -45,6 +45,7 @@ pub fn sort_boolean( // un-efficient; there are much more performant ways of sorting nulls above, anyways. if let Some(limit) = limit { values.truncate(limit); + values.shrink_to_fit(); } PrimitiveArray::::from_data(I::DATA_TYPE, values.into(), None) diff --git a/src/compute/sort/primitive/sort.rs b/src/compute/sort/primitive/sort.rs index 6fcedd80343..de6aa58867b 100644 --- a/src/compute/sort/primitive/sort.rs +++ b/src/compute/sort/primitive/sort.rs @@ -125,6 +125,7 @@ where }; // values are sorted, we can now truncate the remaining. buffer.truncate(limit); + buffer.shrink_to_fit(); (buffer.into(), new_validity.into()) } @@ -154,6 +155,7 @@ where sort_values(&mut buffer.as_mut_slice(), cmp, options.descending, limit); buffer.truncate(limit); + buffer.shrink_to_fit(); (buffer.into(), None) };