Skip to content

Commit c08e03a

Browse files
incr.comp.: Add position() method to TyEncoder.
1 parent 8cbc022 commit c08e03a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/librustc/ty/codec.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use hir::def_id::{DefId, CrateNum};
2020
use middle::const_val::ByteArray;
2121
use rustc_data_structures::fx::FxHashMap;
22-
use rustc_serialize::{Decodable, Decoder, Encoder, Encodable};
22+
use rustc_serialize::{Decodable, Decoder, Encoder, Encodable, opaque};
2323
use std::hash::Hash;
2424
use std::intrinsics;
2525
use ty::{self, Ty, TyCtxt};
@@ -53,6 +53,13 @@ pub trait TyEncoder: Encoder {
5353
fn position(&self) -> usize;
5454
}
5555

56+
impl<'buf> TyEncoder for opaque::Encoder<'buf> {
57+
#[inline]
58+
fn position(&self) -> usize {
59+
self.position()
60+
}
61+
}
62+
5663
/// Encode the given value or a previously cached shorthand.
5764
pub fn encode_with_shorthand<E, T, M>(encoder: &mut E,
5865
value: &T,
@@ -113,6 +120,8 @@ pub trait TyDecoder<'a, 'tcx: 'a>: Decoder {
113120

114121
fn peek_byte(&self) -> u8;
115122

123+
fn position(&self) -> usize;
124+
116125
fn cached_ty_for_shorthand<F>(&mut self,
117126
shorthand: usize,
118127
or_insert_with: F)
@@ -142,7 +151,6 @@ pub fn decode_ty<'a, 'tcx, D>(decoder: &mut D) -> Result<Ty<'tcx>, D::Error>
142151
'tcx: 'a,
143152
{
144153
// Handle shorthands first, if we have an usize > 0x80.
145-
// if self.opaque.data[self.opaque.position()] & 0x80 != 0 {
146154
if decoder.positioned_at_shorthand() {
147155
let pos = decoder.read_usize()?;
148156
assert!(pos >= SHORTHAND_OFFSET);

src/librustc_metadata/decoder.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,21 @@ impl<'doc, 'tcx> Decoder for DecodeContext<'doc, 'tcx> {
217217

218218
impl<'a, 'tcx: 'a> TyDecoder<'a, 'tcx> for DecodeContext<'a, 'tcx> {
219219

220+
#[inline]
220221
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
221222
self.tcx.expect("missing TyCtxt in DecodeContext")
222223
}
223224

225+
#[inline]
224226
fn peek_byte(&self) -> u8 {
225227
self.opaque.data[self.opaque.position()]
226228
}
227229

230+
#[inline]
231+
fn position(&self) -> usize {
232+
self.opaque.position()
233+
}
234+
228235
fn cached_ty_for_shorthand<F>(&mut self,
229236
shorthand: usize,
230237
or_insert_with: F)

0 commit comments

Comments
 (0)