mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-24 22:44:26 +00:00
incr.comp.: Initialize the CachingCodemapView in StableHashingContext lazily.
This commit is contained in:
parent
67c84e05e7
commit
dd501735ac
@ -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 {
|
||||
|
@ -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<Symbol>,
|
||||
|
||||
// Very often, we are hashing something that does not need the
|
||||
// CachingCodemapView, so we initialize it lazily.
|
||||
raw_codemap: &'gcx CodeMap,
|
||||
caching_codemap: Option<CachingCodemapView<'gcx>>,
|
||||
}
|
||||
|
||||
#[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]
|
||||
|
Loading…
Reference in New Issue
Block a user