@@ -368,21 +368,17 @@ impl str {
368368 pub fn to_lowercase ( & self ) -> String {
369369 let out = convert_while_ascii ( self . as_bytes ( ) , u8:: to_ascii_lowercase) ;
370370
371- // Safety: we know this is a valid char boundary since
372- // out.len() is only progressed if ascii bytes are found
373- let rest = unsafe { self . get_unchecked ( out. len ( ) ..) } ;
374-
375371 // Safety: We have written only valid ASCII to our vec
376372 let mut s = unsafe { String :: from_utf8_unchecked ( out) } ;
377373
378- for ( i, c) in rest [ .. ] . char_indices ( ) {
374+ for ( i, c) in self . char_indices ( ) . skip ( s . len ( ) ) {
379375 if c == 'Σ' {
380376 // Σ maps to σ, except at the end of a word where it maps to ς.
381377 // This is the only conditional (contextual) but language-independent mapping
382378 // in `SpecialCasing.txt`,
383379 // so hard-code it rather than have a generic "condition" mechanism.
384380 // See https://github.com/rust-lang/rust/issues/26035
385- map_uppercase_sigma ( rest , i, & mut s )
381+ s . push ( map_uppercase_sigma ( & self , i) ) ;
386382 } else {
387383 match conversions:: to_lower ( c) {
388384 [ a, '\0' , _] => s. push ( a) ,
@@ -400,13 +396,13 @@ impl str {
400396 }
401397 return s;
402398
403- fn map_uppercase_sigma ( from : & str , i : usize , to : & mut String ) {
399+ fn map_uppercase_sigma ( from : & str , i : usize ) -> char {
404400 // See https://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992
405401 // for the definition of `Final_Sigma`.
406402 debug_assert ! ( 'Σ' . len_utf8( ) == 2 ) ;
407403 let is_word_final = case_ignorable_then_cased ( from[ ..i] . chars ( ) . rev ( ) )
408404 && !case_ignorable_then_cased ( from[ i + 2 ..] . chars ( ) ) ;
409- to . push_str ( if is_word_final { "ς" } else { "σ" } ) ;
405+ if is_word_final { 'ς' } else { 'σ' }
410406 }
411407
412408 fn case_ignorable_then_cased < I : Iterator < Item = char > > ( iter : I ) -> bool {
0 commit comments