neilconway commented on code in PR #20352:
URL: https://github.com/apache/datafusion/pull/20352#discussion_r2827829831
##########
datafusion/functions/src/unicode/initcap.rs:
##########
@@ -198,13 +250,16 @@ fn initcap_string(input: &str, container: &mut String) {
let mut prev_is_alphanumeric = false;
if input.is_ascii() {
- for c in input.chars() {
+ container.reserve(input.len());
+ // SAFETY: each byte is ASCII, so the result is valid UTF-8.
+ let out = unsafe { container.as_mut_vec() };
+ for &b in input.as_bytes() {
if prev_is_alphanumeric {
- container.push(c.to_ascii_lowercase());
+ out.push(b.to_ascii_lowercase());
} else {
- container.push(c.to_ascii_uppercase());
- };
- prev_is_alphanumeric = c.is_ascii_alphanumeric();
+ out.push(b.to_ascii_uppercase());
+ }
+ prev_is_alphanumeric = b.is_ascii_alphanumeric();
}
Review Comment:
`out.push()` should update the container's `len`, I believe.
--
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]