about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2017-11-13 15:25:09 +0100
committerMichael Woerister <michaelwoerister@posteo>2017-11-13 15:25:09 +0100
commitc08e03ac46d408a19df480ff5ef7cca4abffdc15 (patch)
treef39dc8d5405c15fb242173fc8f80f3dec28b4254
parent8cbc02238da9f36245d61e1d77ecd214eeed2e6e (diff)
downloadrust-c08e03ac46d408a19df480ff5ef7cca4abffdc15.tar.gz
rust-c08e03ac46d408a19df480ff5ef7cca4abffdc15.zip
incr.comp.: Add position() method to TyEncoder.
-rw-r--r--src/librustc/ty/codec.rs12
-rw-r--r--src/librustc_metadata/decoder.rs7
2 files changed, 17 insertions, 2 deletions
diff --git a/src/librustc/ty/codec.rs b/src/librustc/ty/codec.rs
index 1c793920bf2..164aac303af 100644
--- a/src/librustc/ty/codec.rs
+++ b/src/librustc/ty/codec.rs
@@ -19,7 +19,7 @@
 use hir::def_id::{DefId, CrateNum};
 use middle::const_val::ByteArray;
 use rustc_data_structures::fx::FxHashMap;
-use rustc_serialize::{Decodable, Decoder, Encoder, Encodable};
+use rustc_serialize::{Decodable, Decoder, Encoder, Encodable, opaque};
 use std::hash::Hash;
 use std::intrinsics;
 use ty::{self, Ty, TyCtxt};
@@ -53,6 +53,13 @@ pub trait TyEncoder: Encoder {
     fn position(&self) -> usize;
 }
 
+impl<'buf> TyEncoder for opaque::Encoder<'buf> {
+    #[inline]
+    fn position(&self) -> usize {
+        self.position()
+    }
+}
+
 /// Encode the given value or a previously cached shorthand.
 pub fn encode_with_shorthand<E, T, M>(encoder: &mut E,
                                       value: &T,
@@ -113,6 +120,8 @@ pub trait TyDecoder<'a, 'tcx: 'a>: Decoder {
 
     fn peek_byte(&self) -> u8;
 
+    fn position(&self) -> usize;
+
     fn cached_ty_for_shorthand<F>(&mut self,
                                   shorthand: usize,
                                   or_insert_with: F)
@@ -142,7 +151,6 @@ pub fn decode_ty<'a, 'tcx, D>(decoder: &mut D) -> Result<Ty<'tcx>, D::Error>
           'tcx: 'a,
 {
     // Handle shorthands first, if we have an usize > 0x80.
-    // if self.opaque.data[self.opaque.position()] & 0x80 != 0 {
     if decoder.positioned_at_shorthand() {
         let pos = decoder.read_usize()?;
         assert!(pos >= SHORTHAND_OFFSET);
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index e63037f4da1..5fee7173c87 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -217,14 +217,21 @@ impl<'doc, 'tcx> Decoder for DecodeContext<'doc, 'tcx> {
 
 impl<'a, 'tcx: 'a> TyDecoder<'a, 'tcx> for DecodeContext<'a, 'tcx> {
 
+    #[inline]
     fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
         self.tcx.expect("missing TyCtxt in DecodeContext")
     }
 
+    #[inline]
     fn peek_byte(&self) -> u8 {
         self.opaque.data[self.opaque.position()]
     }
 
+    #[inline]
+    fn position(&self) -> usize {
+        self.opaque.position()
+    }
+
     fn cached_ty_for_shorthand<F>(&mut self,
                                   shorthand: usize,
                                   or_insert_with: F)