@@ -208,7 +208,7 @@ impl Wtf8Buf {
208
208
/// Since WTF-8 is a superset of UTF-8, this always succeeds.
209
209
#[ inline]
210
210
pub fn from_str ( s : & str ) -> Wtf8Buf {
211
- Wtf8Buf { bytes : < [ _ ] > :: to_vec ( s. as_bytes ( ) ) , is_known_utf8 : true }
211
+ Wtf8Buf { bytes : s. as_bytes ( ) . to_vec ( ) , is_known_utf8 : true }
212
212
}
213
213
214
214
pub fn clear ( & mut self ) {
@@ -444,24 +444,17 @@ impl Wtf8Buf {
444
444
///
445
445
/// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “�”)
446
446
pub fn into_string_lossy ( mut self ) -> String {
447
- // Fast path: If we already have UTF-8, we can return it immediately.
448
- if self . is_known_utf8 {
449
- return unsafe { String :: from_utf8_unchecked ( self . bytes ) } ;
450
- }
451
-
452
- let mut pos = 0 ;
453
- loop {
454
- match self . next_surrogate ( pos) {
455
- Some ( ( surrogate_pos, _) ) => {
456
- pos = surrogate_pos + 3 ;
457
- // Surrogates and the replacement character are all 3 bytes,
458
- // so they can substituted in-place.
459
- self . bytes [ surrogate_pos..pos]
460
- . copy_from_slice ( UTF8_REPLACEMENT_CHARACTER . as_bytes ( ) ) ;
461
- }
462
- None => return unsafe { String :: from_utf8_unchecked ( self . bytes ) } ,
447
+ if !self . is_known_utf8 {
448
+ let mut pos = 0 ;
449
+ while let Some ( ( surrogate_pos, _) ) = self . next_surrogate ( pos) {
450
+ pos = surrogate_pos + 3 ;
451
+ // Surrogates and the replacement character are all 3 bytes, so
452
+ // they can substituted in-place.
453
+ self . bytes [ surrogate_pos..pos]
454
+ . copy_from_slice ( UTF8_REPLACEMENT_CHARACTER . as_bytes ( ) ) ;
463
455
}
464
456
}
457
+ unsafe { String :: from_utf8_unchecked ( self . bytes ) }
465
458
}
466
459
467
460
/// Converts this `Wtf8Buf` into a boxed `Wtf8`.
@@ -680,9 +673,8 @@ impl Wtf8 {
680
673
///
681
674
/// This only copies the data if necessary (if it contains any surrogate).
682
675
pub fn to_string_lossy ( & self ) -> Cow < ' _ , str > {
683
- let surrogate_pos = match self . next_surrogate ( 0 ) {
684
- None => return Cow :: Borrowed ( unsafe { str:: from_utf8_unchecked ( & self . bytes ) } ) ,
685
- Some ( ( pos, _) ) => pos,
676
+ let Some ( ( surrogate_pos, _) ) = self . next_surrogate ( 0 ) else {
677
+ return Cow :: Borrowed ( unsafe { str:: from_utf8_unchecked ( & self . bytes ) } ) ;
686
678
} ;
687
679
let wtf8_bytes = & self . bytes ;
688
680
let mut utf8_bytes = Vec :: with_capacity ( self . len ( ) ) ;
@@ -972,7 +964,7 @@ pub struct Wtf8CodePoints<'a> {
972
964
bytes : slice:: Iter < ' a , u8 > ,
973
965
}
974
966
975
- impl < ' a > Iterator for Wtf8CodePoints < ' a > {
967
+ impl Iterator for Wtf8CodePoints < ' _ > {
976
968
type Item = CodePoint ;
977
969
978
970
#[ inline]
@@ -998,7 +990,7 @@ pub struct EncodeWide<'a> {
998
990
999
991
// Copied from libunicode/u_str.rs
1000
992
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1001
- impl < ' a > Iterator for EncodeWide < ' a > {
993
+ impl Iterator for EncodeWide < ' _ > {
1002
994
type Item = u16 ;
1003
995
1004
996
#[ inline]
0 commit comments