comphead commented on code in PR #19558:
URL: https://github.com/apache/datafusion/pull/19558#discussion_r2653776327
##########
datafusion/functions/src/unicode/lpad.rs:
##########
@@ -223,16 +225,20 @@ where
continue;
}
- let graphemes = string.graphemes(true).collect::<Vec<&str>>();
- let fill_chars = fill.chars().collect::<Vec<char>>();
+ // Reuse buffers by clearing and refilling
+ graphemes_buf.clear();
+ graphemes_buf.extend(string.graphemes(true));
- if length < graphemes.len() {
- builder.append_value(graphemes[..length].concat());
- } else if fill_chars.is_empty() {
+ fill_chars_buf.clear();
+ fill_chars_buf.extend(fill.chars());
+
+ if length < graphemes_buf.len() {
+ builder.append_value(graphemes_buf[..length].concat());
+ } else if fill_chars_buf.is_empty() {
builder.append_value(string);
} else {
- for l in 0..length - graphemes.len() {
- let c = *fill_chars.get(l % fill_chars.len()).unwrap();
+ for l in 0..length - graphemes_buf.len() {
+ let c = *fill_chars_buf.get(l %
fill_chars_buf.len()).unwrap();
Review Comment:
nit: it would be better return `Err` instead of `unwrap`
--
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]