File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3704,11 +3704,11 @@ impl String {
37043704 #[ cfg( not( no_global_oom_handling) ) ]
37053705 #[ unstable( feature = "string_make_uplowercase" , issue = "135885" ) ]
37063706 pub fn make_lowercase ( & mut self ) {
3707- let mut wc = WriteChars :: new ( self ) ;
3708- // This is unfortunately paid whether or not you have sigmas in the str
3709- // but it is kind of mandatory because as we are overwriting the source bytes
3710- // we have to compute this information as we go.
3707+ // We will only update the streaming word_final detection if the str contains sigma
3708+ // because it requires table lookups that we consider expensive.
3709+ let has_sigma = self . contains ( 'Σ' ) ;
37113710 let mut word_final_so_far = false ;
3711+ let mut wc = WriteChars :: new ( self ) ;
37123712 while let Some ( u_c) = wc. pop ( ) {
37133713 if u_c == 'Σ' {
37143714 if word_final_so_far && !crate :: str:: case_ignorable_then_cased ( wc. rest ( ) . chars ( ) ) {
@@ -3720,7 +3720,10 @@ impl String {
37203720 } else {
37213721 u_c. to_lowercase ( ) . for_each ( |l_c| wc. write ( l_c) ) ;
37223722 }
3723- word_final_so_far = u_c. is_cased ( ) || ( word_final_so_far && u_c. is_case_ignorable ( ) ) ;
3723+ if has_sigma {
3724+ word_final_so_far =
3725+ u_c. is_cased ( ) || ( word_final_so_far && u_c. is_case_ignorable ( ) ) ;
3726+ }
37243727 }
37253728 }
37263729}
You can’t perform that action at this time.
0 commit comments