diff --git a/datafusion/functions/src/unicode/reverse.rs b/datafusion/functions/src/unicode/reverse.rs index ec6f7a453e7a..0ac86801f7d0 100644 --- a/datafusion/functions/src/unicode/reverse.rs +++ b/datafusion/functions/src/unicode/reverse.rs @@ -118,14 +118,14 @@ pub fn reverse(args: &[ArrayRef]) -> Result { fn reverse_impl<'a, T: OffsetSizeTrait, V: StringArrayType<'a>>( string_array: V, ) -> Result { - let mut builder: GenericStringBuilder = - GenericStringBuilder::with_capacity(string_array.len(), 1024); + let mut builder = GenericStringBuilder::::with_capacity(string_array.len(), 1024); + let mut reversed = String::new(); for string in string_array.iter() { if let Some(s) = string { - let mut reversed = String::with_capacity(s.len()); reversed.extend(s.chars().rev()); - builder.append_value(reversed); + builder.append_value(&reversed); + reversed.clear(); } else { builder.append_null(); }