@@ -573,22 +573,6 @@ impl<'a> MemDecoder<'a> {
573573 self . read_raw_bytes ( N ) . try_into ( ) . unwrap ( )
574574 }
575575
576- // The trait method doesn't have a lifetime parameter, and we need a version of this
577- // that definitely returns a slice based on the underlying storage as opposed to
578- // the Decoder itself in order to implement read_str efficiently.
579- #[ inline]
580- fn read_raw_bytes_inherent ( & mut self , bytes : usize ) -> & ' a [ u8 ] {
581- if bytes > self . remaining ( ) {
582- Self :: decoder_exhausted ( ) ;
583- }
584- // SAFETY: We just checked if this range is in-bounds above.
585- unsafe {
586- let slice = std:: slice:: from_raw_parts ( self . current , bytes) ;
587- self . current = self . current . add ( bytes) ;
588- slice
589- }
590- }
591-
592576 /// While we could manually expose manipulation of the decoder position,
593577 /// all current users of that method would need to reset the position later,
594578 /// incurring the bounds check of set_position twice.
@@ -706,14 +690,22 @@ impl<'a> Decoder for MemDecoder<'a> {
706690 #[ inline]
707691 fn read_str ( & mut self ) -> & str {
708692 let len = self . read_usize ( ) ;
709- let bytes = self . read_raw_bytes_inherent ( len + 1 ) ;
693+ let bytes = self . read_raw_bytes ( len + 1 ) ;
710694 assert ! ( bytes[ len] == STR_SENTINEL ) ;
711695 unsafe { std:: str:: from_utf8_unchecked ( & bytes[ ..len] ) }
712696 }
713697
714698 #[ inline]
715- fn read_raw_bytes ( & mut self , bytes : usize ) -> & [ u8 ] {
716- self . read_raw_bytes_inherent ( bytes)
699+ fn read_raw_bytes ( & mut self , bytes : usize ) -> & ' a [ u8 ] {
700+ if bytes > self . remaining ( ) {
701+ Self :: decoder_exhausted ( ) ;
702+ }
703+ // SAFETY: We just checked if this range is in-bounds above.
704+ unsafe {
705+ let slice = std:: slice:: from_raw_parts ( self . current , bytes) ;
706+ self . current = self . current . add ( bytes) ;
707+ slice
708+ }
717709 }
718710
719711 #[ inline]
0 commit comments