From c65b260441bb6ebc8def8864ef570002644907ac Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Fri, 23 Aug 2024 17:18:58 +0200 Subject: [PATCH] fix primitive capacity leak --- src/array/growable/primitive.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/array/growable/primitive.rs b/src/array/growable/primitive.rs index e443756cb95..89722da8a61 100644 --- a/src/array/growable/primitive.rs +++ b/src/array/growable/primitive.rs @@ -60,7 +60,8 @@ impl<'a, T: NativeType> GrowablePrimitive<'a, T> { #[inline] fn to(&mut self) -> PrimitiveArray { let validity = std::mem::take(&mut self.validity); - let values = std::mem::take(&mut self.values); + let mut values = std::mem::take(&mut self.values); + values.shrink_to_fit(); PrimitiveArray::::new(self.data_type.clone(), values.into(), validity.into()) } @@ -100,7 +101,9 @@ impl<'a, T: NativeType> Growable<'a> for GrowablePrimitive<'a, T> { impl<'a, T: NativeType> From> for PrimitiveArray { #[inline] - fn from(val: GrowablePrimitive<'a, T>) -> Self { - PrimitiveArray::::new(val.data_type, val.values.into(), val.validity.into()) + fn from(mut val: GrowablePrimitive<'a, T>) -> Self { + let mut values = std::mem::take(&mut val.values); + values.shrink_to_fit(); + PrimitiveArray::::new(val.data_type, values.into(), val.validity.into()) } }