@@ -44,7 +44,7 @@ pub use self::methods::{encode_utf8_raw, encode_utf8_raw_unchecked}; // perma-un
4444use  crate :: ascii; 
4545pub ( crate )  use  self :: methods:: EscapeDebugExtArgs ; 
4646use  crate :: error:: Error ; 
47- use  crate :: escape; 
47+ use  crate :: escape:: { AlwaysEscaped ,   EscapeIterInner ,   MaybeEscaped } ; 
4848use  crate :: fmt:: { self ,  Write } ; 
4949use  crate :: iter:: { FusedIterator ,  TrustedLen ,  TrustedRandomAccess ,  TrustedRandomAccessNoCoerce } ; 
5050use  crate :: num:: NonZero ; 
@@ -161,12 +161,12 @@ pub const fn from_digit(num: u32, radix: u32) -> Option<char> {
161161/// [`escape_unicode`]: char::escape_unicode 
162162#[ derive( Clone ,  Debug ) ]  
163163#[ stable( feature = "rust1" ,  since = "1.0.0" ) ]  
164- pub  struct  EscapeUnicode ( escape :: EscapeIterInner < 10 > ) ; 
164+ pub  struct  EscapeUnicode ( EscapeIterInner < 10 ,   AlwaysEscaped > ) ; 
165165
166166impl  EscapeUnicode  { 
167167    #[ inline]  
168168    const  fn  new ( c :  char )  -> Self  { 
169-         Self ( escape :: EscapeIterInner :: unicode ( c) ) 
169+         Self ( EscapeIterInner :: unicode ( c) ) 
170170    } 
171171} 
172172
@@ -215,7 +215,7 @@ impl FusedIterator for EscapeUnicode {}
215215#[ stable( feature = "char_struct_display" ,  since = "1.16.0" ) ]  
216216impl  fmt:: Display  for  EscapeUnicode  { 
217217    fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
218-         f . write_str ( self . 0 . as_str ( ) ) 
218+         fmt :: Display :: fmt ( & self . 0 ,  f ) 
219219    } 
220220} 
221221
@@ -227,22 +227,22 @@ impl fmt::Display for EscapeUnicode {
227227/// [`escape_default`]: char::escape_default 
228228#[ derive( Clone ,  Debug ) ]  
229229#[ stable( feature = "rust1" ,  since = "1.0.0" ) ]  
230- pub  struct  EscapeDefault ( escape :: EscapeIterInner < 10 > ) ; 
230+ pub  struct  EscapeDefault ( EscapeIterInner < 10 ,   AlwaysEscaped > ) ; 
231231
232232impl  EscapeDefault  { 
233233    #[ inline]  
234234    const  fn  printable ( c :  ascii:: Char )  -> Self  { 
235-         Self ( escape :: EscapeIterInner :: ascii ( c. to_u8 ( ) ) ) 
235+         Self ( EscapeIterInner :: ascii ( c. to_u8 ( ) ) ) 
236236    } 
237237
238238    #[ inline]  
239239    const  fn  backslash ( c :  ascii:: Char )  -> Self  { 
240-         Self ( escape :: EscapeIterInner :: backslash ( c) ) 
240+         Self ( EscapeIterInner :: backslash ( c) ) 
241241    } 
242242
243243    #[ inline]  
244244    const  fn  unicode ( c :  char )  -> Self  { 
245-         Self ( escape :: EscapeIterInner :: unicode ( c) ) 
245+         Self ( EscapeIterInner :: unicode ( c) ) 
246246    } 
247247} 
248248
@@ -290,8 +290,9 @@ impl FusedIterator for EscapeDefault {}
290290
291291#[ stable( feature = "char_struct_display" ,  since = "1.16.0" ) ]  
292292impl  fmt:: Display  for  EscapeDefault  { 
293+     #[ inline]  
293294    fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
294-         f . write_str ( self . 0 . as_str ( ) ) 
295+         fmt :: Display :: fmt ( & self . 0 ,  f ) 
295296    } 
296297} 
297298
@@ -303,37 +304,22 @@ impl fmt::Display for EscapeDefault {
303304/// [`escape_debug`]: char::escape_debug 
304305#[ stable( feature = "char_escape_debug" ,  since = "1.20.0" ) ]  
305306#[ derive( Clone ,  Debug ) ]  
306- pub  struct  EscapeDebug ( EscapeDebugInner ) ; 
307- 
308- #[ derive( Clone ,  Debug ) ]  
309- // Note: It’s possible to manually encode the EscapeDebugInner inside of 
310- // EscapeIterInner (e.g. with alive=254..255 indicating that data[0..4] holds 
311- // a char) which would likely result in a more optimised code.  For now we use 
312- // the option easier to implement. 
313- enum  EscapeDebugInner  { 
314-     Bytes ( escape:: EscapeIterInner < 10 > ) , 
315-     Char ( char ) , 
316- } 
307+ pub  struct  EscapeDebug ( EscapeIterInner < 10 ,  MaybeEscaped > ) ; 
317308
318309impl  EscapeDebug  { 
319310    #[ inline]  
320311    const  fn  printable ( chr :  char )  -> Self  { 
321-         Self ( EscapeDebugInner :: Char ( chr) ) 
312+         Self ( EscapeIterInner :: printable ( chr) ) 
322313    } 
323314
324315    #[ inline]  
325316    const  fn  backslash ( c :  ascii:: Char )  -> Self  { 
326-         Self ( EscapeDebugInner :: Bytes ( escape :: EscapeIterInner :: backslash ( c) ) ) 
317+         Self ( EscapeIterInner :: backslash ( c) ) 
327318    } 
328319
329320    #[ inline]  
330321    const  fn  unicode ( c :  char )  -> Self  { 
331-         Self ( EscapeDebugInner :: Bytes ( escape:: EscapeIterInner :: unicode ( c) ) ) 
332-     } 
333- 
334-     #[ inline]  
335-     fn  clear ( & mut  self )  { 
336-         self . 0  = EscapeDebugInner :: Bytes ( escape:: EscapeIterInner :: empty ( ) ) ; 
322+         Self ( EscapeIterInner :: unicode ( c) ) 
337323    } 
338324} 
339325
@@ -343,13 +329,7 @@ impl Iterator for EscapeDebug {
343329
344330    #[ inline]  
345331    fn  next ( & mut  self )  -> Option < char >  { 
346-         match  self . 0  { 
347-             EscapeDebugInner :: Bytes ( ref  mut  bytes)  => bytes. next ( ) . map ( char:: from) , 
348-             EscapeDebugInner :: Char ( chr)  => { 
349-                 self . clear ( ) ; 
350-                 Some ( chr) 
351-             } 
352-         } 
332+         self . 0 . next ( ) 
353333    } 
354334
355335    #[ inline]  
@@ -367,10 +347,7 @@ impl Iterator for EscapeDebug {
367347#[ stable( feature = "char_escape_debug" ,  since = "1.20.0" ) ]  
368348impl  ExactSizeIterator  for  EscapeDebug  { 
369349    fn  len ( & self )  -> usize  { 
370-         match  & self . 0  { 
371-             EscapeDebugInner :: Bytes ( bytes)  => bytes. len ( ) , 
372-             EscapeDebugInner :: Char ( _)  => 1 , 
373-         } 
350+         self . 0 . len ( ) 
374351    } 
375352} 
376353
@@ -379,11 +356,9 @@ impl FusedIterator for EscapeDebug {}
379356
380357#[ stable( feature = "char_escape_debug" ,  since = "1.20.0" ) ]  
381358impl  fmt:: Display  for  EscapeDebug  { 
359+     #[ inline]  
382360    fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
383-         match  & self . 0  { 
384-             EscapeDebugInner :: Bytes ( bytes)  => f. write_str ( bytes. as_str ( ) ) , 
385-             EscapeDebugInner :: Char ( chr)  => f. write_char ( * chr) , 
386-         } 
361+         fmt:: Display :: fmt ( & self . 0 ,  f) 
387362    } 
388363} 
389364
@@ -480,6 +455,7 @@ macro_rules! casemappingiter_impls {
480455
481456        #[ stable( feature = "char_struct_display" ,  since = "1.16.0" ) ] 
482457        impl  fmt:: Display  for  $ITER_NAME { 
458+             #[ inline] 
483459            fn  fmt( & self ,  f:  & mut  fmt:: Formatter <' _>)  -> fmt:: Result  { 
484460                fmt:: Display :: fmt( & self . 0 ,  f) 
485461            } 
0 commit comments