@@ -169,13 +169,12 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
169
169
170
170
// Decode the *position* of the footer, which can be found in the
171
171
// last 8 bytes of the file.
172
- decoder. set_position ( data. len ( ) - IntEncodedWithFixedSize :: ENCODED_SIZE ) ;
173
- let footer_pos = IntEncodedWithFixedSize :: decode ( & mut decoder) . 0 as usize ;
174
-
172
+ let footer_pos = decoder
173
+ . with_position ( decoder. len ( ) - IntEncodedWithFixedSize :: ENCODED_SIZE , |decoder| {
174
+ IntEncodedWithFixedSize :: decode ( decoder) . 0 as usize
175
+ } ) ;
175
176
// Decode the file footer, which contains all the lookup tables, etc.
176
- decoder. set_position ( footer_pos) ;
177
-
178
- decode_tagged ( & mut decoder, TAG_FILE_FOOTER )
177
+ decoder. with_position ( footer_pos, |decoder| decode_tagged ( decoder, TAG_FILE_FOOTER ) )
179
178
} ;
180
179
181
180
Self {
@@ -522,29 +521,13 @@ impl<'a, 'tcx> CacheDecoder<'a, 'tcx> {
522
521
}
523
522
}
524
523
525
- trait DecoderWithPosition : Decoder {
526
- fn position ( & self ) -> usize ;
527
- }
528
-
529
- impl < ' a > DecoderWithPosition for MemDecoder < ' a > {
530
- fn position ( & self ) -> usize {
531
- self . position ( )
532
- }
533
- }
534
-
535
- impl < ' a , ' tcx > DecoderWithPosition for CacheDecoder < ' a , ' tcx > {
536
- fn position ( & self ) -> usize {
537
- self . opaque . position ( )
538
- }
539
- }
540
-
541
524
// Decodes something that was encoded with `encode_tagged()` and verify that the
542
525
// tag matches and the correct amount of bytes was read.
543
526
fn decode_tagged < D , T , V > ( decoder : & mut D , expected_tag : T ) -> V
544
527
where
545
528
T : Decodable < D > + Eq + std:: fmt:: Debug ,
546
529
V : Decodable < D > ,
547
- D : DecoderWithPosition ,
530
+ D : Decoder ,
548
531
{
549
532
let start_pos = decoder. position ( ) ;
550
533
@@ -568,16 +551,6 @@ impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
568
551
self . tcx
569
552
}
570
553
571
- #[ inline]
572
- fn position ( & self ) -> usize {
573
- self . opaque . position ( )
574
- }
575
-
576
- #[ inline]
577
- fn peek_byte ( & self ) -> u8 {
578
- self . opaque . data [ self . opaque . position ( ) ]
579
- }
580
-
581
554
fn cached_ty_for_shorthand < F > ( & mut self , shorthand : usize , or_insert_with : F ) -> Ty < ' tcx >
582
555
where
583
556
F : FnOnce ( & mut Self ) -> Ty < ' tcx > ,
@@ -600,9 +573,9 @@ impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> {
600
573
where
601
574
F : FnOnce ( & mut Self ) -> R ,
602
575
{
603
- debug_assert ! ( pos < self . opaque. data . len( ) ) ;
576
+ debug_assert ! ( pos < self . opaque. len( ) ) ;
604
577
605
- let new_opaque = MemDecoder :: new ( self . opaque . data , pos) ;
578
+ let new_opaque = MemDecoder :: new ( self . opaque . data ( ) , pos) ;
606
579
let old_opaque = mem:: replace ( & mut self . opaque , new_opaque) ;
607
580
let r = f ( self ) ;
608
581
self . opaque = old_opaque;
@@ -743,17 +716,12 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for Symbol {
743
716
SYMBOL_OFFSET => {
744
717
// read str offset
745
718
let pos = d. read_usize ( ) ;
746
- let old_pos = d. opaque . position ( ) ;
747
719
748
720
// move to str offset and read
749
- d. opaque . set_position ( pos) ;
750
- let s = d. read_str ( ) ;
751
- let sym = Symbol :: intern ( s) ;
752
-
753
- // restore position
754
- d. opaque . set_position ( old_pos) ;
755
-
756
- sym
721
+ d. opaque . with_position ( pos, |d| {
722
+ let s = d. read_str ( ) ;
723
+ Symbol :: intern ( s)
724
+ } )
757
725
}
758
726
SYMBOL_PREINTERNED => {
759
727
let symbol_index = d. read_u32 ( ) ;
0 commit comments