Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions library/alloc/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,7 @@ impl [u8] {
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[inline]
pub fn to_ascii_uppercase(&self) -> Vec<u8> {
let mut me = self.to_vec();
me.make_ascii_uppercase();
me
self.iter().map(|b| b.to_ascii_uppercase()).collect()
}

/// Returns a vector containing a copy of this slice where each byte
Expand All @@ -660,9 +658,7 @@ impl [u8] {
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[inline]
pub fn to_ascii_lowercase(&self) -> Vec<u8> {
let mut me = self.to_vec();
me.make_ascii_lowercase();
me
self.iter().map(|b| b.to_ascii_lowercase()).collect()
}
}

Expand Down
14 changes: 8 additions & 6 deletions library/alloc/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,10 @@ impl str {
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[inline]
pub fn to_ascii_uppercase(&self) -> String {
let mut s = self.to_owned();
s.make_ascii_uppercase();
s
let bytes = self.as_bytes().to_ascii_uppercase();
// SAFETY: ASCII case conversion only maps a-z to A-Z and leaves
// all other bytes unchanged as valid UTF-8
unsafe { String::from_utf8_unchecked(bytes) }
}

/// Returns a copy of this string where each character is mapped to its
Expand Down Expand Up @@ -876,9 +877,10 @@ impl str {
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[inline]
pub fn to_ascii_lowercase(&self) -> String {
let mut s = self.to_owned();
s.make_ascii_lowercase();
s
let bytes = self.as_bytes().to_ascii_lowercase();
// SAFETY: ASCII case conversion only maps A-Z to a-z and leaves
// all other bytes unchanged as valid UTF-8
unsafe { String::from_utf8_unchecked(bytes) }
}
}

Expand Down
Loading