alamb commented on code in PR #21849:
URL: https://github.com/apache/datafusion/pull/21849#discussion_r3156790407


##########
datafusion/functions/src/string/replace.rs:
##########
@@ -188,25 +209,44 @@ fn replace<T: OffsetSizeTrait>(args: &[ArrayRef]) -> 
Result<ArrayRef> {
     let from_array = as_generic_string_array::<T>(&args[1])?;
     let to_array = as_generic_string_array::<T>(&args[2])?;
 
-    let mut builder = GenericStringBuilder::<T>::new();
+    let len = string_array.len();
+    let mut builder = GenericStringArrayBuilder::<T>::with_capacity(len, 0);
     let mut buffer = String::new();
+    let nulls = NullBuffer::union(
+        NullBuffer::union(string_array.nulls(), from_array.nulls()).as_ref(),
+        to_array.nulls(),
+    );
 
-    for ((string, from), to) in string_array
-        .iter()
-        .zip(from_array.iter())
-        .zip(to_array.iter())
-    {
-        match (string, from, to) {
-            (Some(string), Some(from), Some(to)) => {
-                buffer.clear();
-                replace_into_string(&mut buffer, string, from, to);
-                builder.append_value(&buffer);
+    // Hoist the nulls.is_some() check out of the loop. LLVM unswitches this
+    // automatically today, but kept explicit so the no-nulls fast path is not

Review Comment:
   👍 



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