martin-g commented on code in PR #19571:
URL: https://github.com/apache/datafusion/pull/19571#discussion_r2657501800
##########
datafusion/functions/src/unicode/left.rs:
##########
@@ -139,14 +139,22 @@ fn left_impl<'a, T: OffsetSizeTrait, V:
ArrayAccessor<Item = &'a str>>(
n_array: &Int64Array,
) -> Result<ArrayRef> {
let iter = ArrayIter::new(string_array);
+ let mut chars_buf = Vec::new();
let result = iter
.zip(n_array.iter())
.map(|(string, n)| match (string, n) {
(Some(string), Some(n)) => match n.cmp(&0) {
Ordering::Less => {
- let len = string.chars().count() as i64;
+ // Collect chars once and reuse for both count and take
+ chars_buf.clear();
+ chars_buf.extend(string.chars());
+ let len = chars_buf.len() as i64;
+
Some(if n.abs() < len {
Review Comment:
minor improvement: calling .abs() on MIN will lead to problems (crash in dev
and wrapping in release).
i64::MIN is a corner case, so I guess no one will complain that it is not
supported here.
I also tried with `if n + len > 0` but then it was 3% slower on my machine.
```suggestion
Some(if n != i64::MIN && n.abs() < len {
```
--
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]