viirya commented on code in PR #19558:
URL: https://github.com/apache/datafusion/pull/19558#discussion_r2653509673


##########
datafusion/functions/src/unicode/rpad.rs:
##########
@@ -268,18 +272,20 @@ where
                                     );
                                 }
                                 let length = if length < 0 { 0 } else { length 
as usize };
-                                let graphemes =
-                                    
string.graphemes(true).collect::<Vec<&str>>();
+                                // Reuse buffer by clearing and refilling
+                                graphemes_buf.clear();
+                                graphemes_buf.extend(string.graphemes(true));
 
-                                if length < graphemes.len() {
-                                    
builder.append_value(graphemes[..length].concat());
+                                if length < graphemes_buf.len() {
+                                    builder
+                                        
.append_value(graphemes_buf[..length].concat());
                                 } else if fill.is_empty() {
                                     builder.append_value(string);
                                 } else {
                                     builder.write_str(string)?;
                                     fill.chars()
                                         .cycle()
-                                        .take(length - graphemes.len())
+                                        .take(length - graphemes_buf.len())
                                         .for_each(|ch| 
builder.write_char(ch).unwrap());

Review Comment:
   rpad now also benefits from fill_chars_buf optimization.



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