From c08e03ac46d408a19df480ff5ef7cca4abffdc15 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 13 Nov 2017 15:25:09 +0100 Subject: [PATCH] incr.comp.: Add position() method to TyEncoder. --- src/librustc/ty/codec.rs | 12 ++++++++++-- src/librustc_metadata/decoder.rs | 7 +++++++ 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(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(&mut self, shorthand: usize, or_insert_with: F) @@ -142,7 +151,6 @@ pub fn decode_ty<'a, 'tcx, D>(decoder: &mut D) -> Result, 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(&mut self, shorthand: usize, or_insert_with: F)