neilconway commented on code in PR #21405:
URL: https://github.com/apache/datafusion/pull/21405#discussion_r3045972591


##########
datafusion/functions/src/unicode/rpad.rs:
##########
@@ -492,16 +484,15 @@ where
                         builder.append_value("");
                     }
                 } else {
-                    graphemes_buf.clear();
-                    graphemes_buf.extend(string.graphemes(true));
+                    let char_count = string.chars().count();
 
-                    if target_len < graphemes_buf.len() {
-                        let end: usize =
-                            graphemes_buf[..target_len].iter().map(|g| 
g.len()).sum();
-                        builder.append_value(&string[..end]);
+                    if target_len < char_count {
+                        builder.append_value(
+                            &string[..byte_offset_of_char(string, target_len)],
+                        );
                     } else {
                         builder.write_str(string)?;
-                        for _ in 0..(target_len - graphemes_buf.len()) {
+                        for _ in 0..(target_len - char_count) {

Review Comment:
   You could, although this is just what the pre-existing code did. I think 
`repeat` would allocate and `write_str` in a loop will not; not sure offhand 
which is better but I'd think it's a wash? We could look at this in a followup 
PR if you'd like?



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