diff --git a/src/librustc/ich/caching_codemap_view.rs b/src/librustc/ich/caching_codemap_view.rs index 49e18f100cf..71e442b3bb2 100644 --- a/src/librustc/ich/caching_codemap_view.rs +++ b/src/librustc/ich/caching_codemap_view.rs @@ -11,7 +11,6 @@ use std::rc::Rc; use syntax::codemap::CodeMap; use syntax_pos::{BytePos, FileMap}; -use ty::TyCtxt; #[derive(Clone)] struct CacheEntry { @@ -23,15 +22,14 @@ struct CacheEntry { file_index: usize, } -pub struct CachingCodemapView<'tcx> { - codemap: &'tcx CodeMap, +pub struct CachingCodemapView<'cm> { + codemap: &'cm CodeMap, line_cache: [CacheEntry; 3], time_stamp: usize, } -impl<'gcx> CachingCodemapView<'gcx> { - pub fn new<'a, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> CachingCodemapView<'gcx> { - let codemap = tcx.sess.codemap(); +impl<'cm> CachingCodemapView<'cm> { + pub fn new(codemap: &'cm CodeMap) -> CachingCodemapView<'cm> { let files = codemap.files(); let first_file = files[0].clone(); let entry = CacheEntry { diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index 0932c5ce8fb..3f9590a45c6 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -21,6 +21,7 @@ use std::collections::HashMap; use syntax::ast; use syntax::attr; +use syntax::codemap::CodeMap; use syntax::ext::hygiene::SyntaxContext; use syntax::symbol::Symbol; use syntax_pos::Span; @@ -36,13 +37,17 @@ use rustc_data_structures::accumulate_vec::AccumulateVec; /// things (e.g. each DefId/DefPath is only hashed once). pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, - codemap: CachingCodemapView<'gcx>, hash_spans: bool, hash_bodies: bool, overflow_checks_enabled: bool, node_id_hashing_mode: NodeIdHashingMode, // A sorted array of symbol keys for fast lookup. ignored_attr_names: Vec, + + // Very often, we are hashing something that does not need the + // CachingCodemapView, so we initialize it lazily. + raw_codemap: &'gcx CodeMap, + caching_codemap: Option>, } #[derive(PartialEq, Eq, Clone, Copy)] @@ -66,7 +71,8 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> { StableHashingContext { tcx, - codemap: CachingCodemapView::new(tcx), + caching_codemap: None, + raw_codemap: tcx.sess.codemap(), hash_spans: hash_spans_initial, hash_bodies: true, overflow_checks_enabled: check_overflow_initial, @@ -132,7 +138,15 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> { #[inline] pub fn codemap(&mut self) -> &mut CachingCodemapView<'gcx> { - &mut self.codemap + match self.caching_codemap { + Some(ref mut cm) => { + cm + } + ref mut none => { + *none = Some(CachingCodemapView::new(self.raw_codemap)); + none.as_mut().unwrap() + } + } } #[inline]