File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -639,7 +639,9 @@ impl [u8] {
639639 #[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
640640 #[ inline]
641641 pub fn to_ascii_uppercase ( & self ) -> Vec < u8 > {
642- self . iter ( ) . map ( |b| b. to_ascii_uppercase ( ) ) . collect ( )
642+ let mut me = self . to_vec ( ) ;
643+ me. make_ascii_uppercase ( ) ;
644+ me
643645 }
644646
645647 /// Returns a vector containing a copy of this slice where each byte
@@ -658,7 +660,9 @@ impl [u8] {
658660 #[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
659661 #[ inline]
660662 pub fn to_ascii_lowercase ( & self ) -> Vec < u8 > {
661- self . iter ( ) . map ( |b| b. to_ascii_lowercase ( ) ) . collect ( )
663+ let mut me = self . to_vec ( ) ;
664+ me. make_ascii_lowercase ( ) ;
665+ me
662666 }
663667}
664668
Original file line number Diff line number Diff line change @@ -844,10 +844,9 @@ impl str {
844844 #[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
845845 #[ inline]
846846 pub fn to_ascii_uppercase ( & self ) -> String {
847- let bytes = self . as_bytes ( ) . to_ascii_uppercase ( ) ;
848- // SAFETY: ASCII case conversion only maps a-z to A-Z and leaves
849- // all other bytes unchanged as valid UTF-8
850- unsafe { String :: from_utf8_unchecked ( bytes) }
847+ let mut s = self . to_owned ( ) ;
848+ s. make_ascii_uppercase ( ) ;
849+ s
851850 }
852851
853852 /// Returns a copy of this string where each character is mapped to its
@@ -877,10 +876,9 @@ impl str {
877876 #[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
878877 #[ inline]
879878 pub fn to_ascii_lowercase ( & self ) -> String {
880- let bytes = self . as_bytes ( ) . to_ascii_lowercase ( ) ;
881- // SAFETY: ASCII case conversion only maps A-Z to a-z and leaves
882- // all other bytes unchanged as valid UTF-8
883- unsafe { String :: from_utf8_unchecked ( bytes) }
879+ let mut s = self . to_owned ( ) ;
880+ s. make_ascii_lowercase ( ) ;
881+ s
884882 }
885883}
886884
You can’t perform that action at this time.
0 commit comments