diff options
| author | Oliver Schneider <git-no-reply-9879165716479413131@oli-obk.de> | 2018-04-11 10:47:52 +0200 |
|---|---|---|
| committer | Oliver Schneider <git-no-reply-9879165716479413131@oli-obk.de> | 2018-04-14 12:21:46 +0200 |
| commit | 6f251c2a0318cc4b61c7f9e96113d2e31175d8fc (patch) | |
| tree | 8625f057366df8452e5ec30c8a9fbc04abea0742 /src/librustc_metadata/decoder.rs | |
| parent | 62c0501be8a0fa5e511a45ed9ffbcef42094e9ad (diff) | |
| download | rust-6f251c2a0318cc4b61c7f9e96113d2e31175d8fc.tar.gz rust-6f251c2a0318cc4b61c7f9e96113d2e31175d8fc.zip | |
Use `LazySeq` instead of `Vec`
Diffstat (limited to 'src/librustc_metadata/decoder.rs')
| -rw-r--r-- | src/librustc_metadata/decoder.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 9173d128274..c69ee180dc9 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -59,6 +59,9 @@ pub struct DecodeContext<'a, 'tcx: 'a> { // interpreter allocation cache interpret_alloc_cache: FxHashMap<usize, interpret::AllocId>, + + // Read from the LazySeq CrateRoot::inpterpret_alloc_index on demand + interpret_alloc_index: Option<Vec<u32>>, } /// Abstract over the various ways one can create metadata decoders. @@ -78,6 +81,7 @@ pub trait Metadata<'a, 'tcx>: Copy { last_filemap_index: 0, lazy_state: LazyState::NoNode, interpret_alloc_cache: FxHashMap::default(), + interpret_alloc_index: None, } } } @@ -176,6 +180,17 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { self.lazy_state = LazyState::Previous(position + min_size); Ok(position) } + + fn interpret_alloc(&mut self, idx: usize) -> usize { + if let Some(index) = self.interpret_alloc_index.as_mut() { + return index[idx] as usize; + } + let index = self.cdata().root.interpret_alloc_index; + let index: Vec<u32> = index.decode(self.cdata()).collect(); + let pos = index[idx]; + self.interpret_alloc_index = Some(index); + pos as usize + } } impl<'a, 'tcx: 'a> TyDecoder<'a, 'tcx> for DecodeContext<'a, 'tcx> { @@ -292,11 +307,8 @@ impl<'a, 'tcx> SpecializedDecoder<interpret::AllocId> for DecodeContext<'a, 'tcx if let Some(cached) = self.interpret_alloc_cache.get(&idx).cloned() { return Ok(cached); } - let pos = self - .cdata() - .root - .interpret_alloc_index[idx]; - self.with_position(pos as usize, |this| { + let pos = self.interpret_alloc(idx); + self.with_position(pos, |this| { interpret::specialized_decode_alloc_id( this, tcx, |
