@@ -368,21 +368,17 @@ impl str {
368
368
pub fn to_lowercase ( & self ) -> String {
369
369
let out = convert_while_ascii ( self . as_bytes ( ) , u8:: to_ascii_lowercase) ;
370
370
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
-
375
371
// Safety: We have written only valid ASCII to our vec
376
372
let mut s = unsafe { String :: from_utf8_unchecked ( out) } ;
377
373
378
- for ( i, c) in rest [ .. ] . char_indices ( ) {
374
+ for ( i, c) in self . char_indices ( ) . skip ( s . len ( ) ) {
379
375
if c == 'Σ' {
380
376
// Σ maps to σ, except at the end of a word where it maps to ς.
381
377
// This is the only conditional (contextual) but language-independent mapping
382
378
// in `SpecialCasing.txt`,
383
379
// so hard-code it rather than have a generic "condition" mechanism.
384
380
// 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) ) ;
386
382
} else {
387
383
match conversions:: to_lower ( c) {
388
384
[ a, '\0' , _] => s. push ( a) ,
@@ -400,13 +396,13 @@ impl str {
400
396
}
401
397
return s;
402
398
403
- fn map_uppercase_sigma ( from : & str , i : usize , to : & mut String ) {
399
+ fn map_uppercase_sigma ( from : & str , i : usize ) -> char {
404
400
// See https://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992
405
401
// for the definition of `Final_Sigma`.
406
402
debug_assert ! ( 'Σ' . len_utf8( ) == 2 ) ;
407
403
let is_word_final = case_ignorable_then_cased ( from[ ..i] . chars ( ) . rev ( ) )
408
404
&& !case_ignorable_then_cased ( from[ i + 2 ..] . chars ( ) ) ;
409
- to . push_str ( if is_word_final { "ς" } else { "σ" } ) ;
405
+ if is_word_final { 'ς' } else { 'σ' }
410
406
}
411
407
412
408
fn case_ignorable_then_cased < I : Iterator < Item = char > > ( iter : I ) -> bool {
0 commit comments