@@ -219,7 +219,7 @@ impl Wtf8Buf {
219
219
/// Since WTF-8 is a superset of UTF-8, this always succeeds.
220
220
#[ inline]
221
221
pub fn from_str ( s : & str ) -> Wtf8Buf {
222
- Wtf8Buf { bytes : < [ _ ] > :: to_vec ( s. as_bytes ( ) ) , is_known_utf8 : true }
222
+ Wtf8Buf { bytes : s. as_bytes ( ) . to_vec ( ) , is_known_utf8 : true }
223
223
}
224
224
225
225
pub fn clear ( & mut self ) {
@@ -467,24 +467,17 @@ impl Wtf8Buf {
467
467
///
468
468
/// Surrogates are replaced with `"\u{FFFD}"` (the replacement character “�”)
469
469
pub fn into_string_lossy ( mut self ) -> String {
470
- // Fast path: If we already have UTF-8, we can return it immediately.
471
- if self . is_known_utf8 {
472
- return unsafe { String :: from_utf8_unchecked ( self . bytes ) } ;
473
- }
474
-
475
- let mut pos = 0 ;
476
- loop {
477
- match self . next_surrogate ( pos) {
478
- Some ( ( surrogate_pos, _) ) => {
479
- pos = surrogate_pos + 3 ;
480
- // Surrogates and the replacement character are all 3 bytes,
481
- // so they can substituted in-place.
482
- self . bytes [ surrogate_pos..pos]
483
- . copy_from_slice ( UTF8_REPLACEMENT_CHARACTER . as_bytes ( ) ) ;
484
- }
485
- None => return unsafe { String :: from_utf8_unchecked ( self . bytes ) } ,
470
+ if !self . is_known_utf8 {
471
+ let mut pos = 0 ;
472
+ while let Some ( ( surrogate_pos, _) ) = self . next_surrogate ( pos) {
473
+ pos = surrogate_pos + 3 ;
474
+ // Surrogates and the replacement character are all 3 bytes, so
475
+ // they can substituted in-place.
476
+ self . bytes [ surrogate_pos..pos]
477
+ . copy_from_slice ( UTF8_REPLACEMENT_CHARACTER . as_bytes ( ) ) ;
486
478
}
487
479
}
480
+ unsafe { String :: from_utf8_unchecked ( self . bytes ) }
488
481
}
489
482
490
483
/// Converts this `Wtf8Buf` into a boxed `Wtf8`.
@@ -703,9 +696,8 @@ impl Wtf8 {
703
696
///
704
697
/// This only copies the data if necessary (if it contains any surrogate).
705
698
pub fn to_string_lossy ( & self ) -> Cow < ' _ , str > {
706
- let surrogate_pos = match self . next_surrogate ( 0 ) {
707
- None => return Cow :: Borrowed ( unsafe { str:: from_utf8_unchecked ( & self . bytes ) } ) ,
708
- Some ( ( pos, _) ) => pos,
699
+ let Some ( ( surrogate_pos, _) ) = self . next_surrogate ( 0 ) else {
700
+ return Cow :: Borrowed ( unsafe { str:: from_utf8_unchecked ( & self . bytes ) } ) ;
709
701
} ;
710
702
let wtf8_bytes = & self . bytes ;
711
703
let mut utf8_bytes = Vec :: with_capacity ( self . len ( ) ) ;
@@ -995,7 +987,7 @@ pub struct Wtf8CodePoints<'a> {
995
987
bytes : slice:: Iter < ' a , u8 > ,
996
988
}
997
989
998
- impl < ' a > Iterator for Wtf8CodePoints < ' a > {
990
+ impl Iterator for Wtf8CodePoints < ' _ > {
999
991
type Item = CodePoint ;
1000
992
1001
993
#[ inline]
@@ -1021,7 +1013,7 @@ pub struct EncodeWide<'a> {
1021
1013
1022
1014
// Copied from libunicode/u_str.rs
1023
1015
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1024
- impl < ' a > Iterator for EncodeWide < ' a > {
1016
+ impl Iterator for EncodeWide < ' _ > {
1025
1017
type Item = u16 ;
1026
1018
1027
1019
#[ inline]
0 commit comments