comphead commented on code in PR #19547:
URL: https://github.com/apache/datafusion/pull/19547#discussion_r2665844747


##########
datafusion/functions/src/string/concat_ws.rs:
##########
@@ -136,43 +136,22 @@ impl ScalarUDFImpl for ConcatWsFunc {
                 None => return internal_err!("Expected string literal, got 
{scalar:?}"),
             };
 
-            let mut result = String::new();
-            // iterator over Option<str>
-            let iter = &mut args[1..].iter().map(|arg| {
+            let mut values = Vec::with_capacity(args.len() - 1);
+            for arg in &args[1..] {
                 let ColumnarValue::Scalar(scalar) = arg else {
                     // loop above checks for all args being scalar
                     unreachable!()
                 };
-                scalar.try_as_str()
-            });
-
-            // append first non null arg
-            for scalar in iter.by_ref() {
-                match scalar {
-                    Some(Some(s)) => {
-                        result.push_str(s);
-                        break;
-                    }
-                    Some(None) => {} // null literal string
-                    None => {
-                        return internal_err!("Expected string literal, got 
{scalar:?}");
-                    }
-                }
-            }
 
-            // handle subsequent non null args
-            for scalar in iter.by_ref() {
-                match scalar {
-                    Some(Some(s)) => {
-                        result.push_str(sep);
-                        result.push_str(s);
-                    }
+                match scalar.try_as_str() {
+                    Some(Some(v)) => values.push(v),

Review Comment:
   wondering should inserting a sep after the token be faster than calling 
`join` later? 
   ```
   values.push(sep)
   values.push(v)
   ```



-- 
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]

Reply via email to