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


##########
datafusion/functions/src/unicode/lpad.rs:
##########
@@ -270,22 +269,19 @@ fn lpad_scalar_unicode<'a, V: StringArrayType<'a> + Copy, 
T: OffsetSizeTrait>(
     let data_capacity = string_array.len().saturating_mul(target_len * 4);
     let mut builder =
         GenericStringBuilder::<T>::with_capacity(string_array.len(), 
data_capacity);
-    let mut graphemes_buf = Vec::new();
 
     for maybe_string in string_array.iter() {
         match maybe_string {
             Some(string) => {
-                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)]);

Review Comment:
   Good idea! I added a helper here to do this in one place and DRY up the code 
a bit.



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