simonvandel commented on code in PR #14025:
URL: https://github.com/apache/datafusion/pull/14025#discussion_r1904839947
##########
datafusion/functions/src/unicode/reverse.rs:
##########
@@ -116,14 +115,23 @@ pub fn reverse<T: OffsetSizeTrait>(args: &[ArrayRef]) ->
Result<ArrayRef> {
}
}
-fn reverse_impl<'a, T: OffsetSizeTrait, V: ArrayAccessor<Item = &'a str>>(
+fn reverse_impl<'a, T: OffsetSizeTrait, V: StringArrayType<'a>>(
string_array: V,
) -> Result<ArrayRef> {
- let result = ArrayIter::new(string_array)
- .map(|string| string.map(|string: &str|
string.chars().rev().collect::<String>()))
- .collect::<GenericStringArray<T>>();
+ let mut builder: GenericStringBuilder<T> =
+ GenericStringBuilder::with_capacity(string_array.len(), 1024);
+
+ for string in string_array.iter() {
+ if let Some(s) = string {
+ let mut reversed = String::with_capacity(s.len());
Review Comment:
I wonder if this allocation can be removed by using the Write impl? See
https://arrow.apache.org/rust/arrow/array/type.GenericStringBuilder.html#example-incrementally-writing-strings-with-stdfmtwrite
Perhaps by iterating through the rev iterator, writing chars one at a time.
---
If the above is slower, it could also be interesting to see if reusing the
String allocation with a clear() on every loop is faster
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]