Skip to content

Commit

Permalink
Auto merge of #43840 - arielb1:unused-reads-beta, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
[beta] syntax: avoid loading the same source-file multiple times

We already had a cache for file contents, but we read the source-file
before testing the cache, causing obvious slowness, so this just avoids
loading the source-file when the cache already has the contents.
  • Loading branch information
bors committed Aug 13, 2017
2 parents f38ffa8 + a3387eb commit 6807eef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/libsyntax/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,9 @@ impl CodeMapper for CodeMap {
sp
}
fn ensure_filemap_source_present(&self, file_map: Rc<FileMap>) -> bool {
let src = self.file_loader.read_file(Path::new(&file_map.name)).ok();
return file_map.add_external_src(src)
file_map.add_external_src(
|| self.file_loader.read_file(Path::new(&file_map.name)).ok()
)
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,11 @@ impl FileMap {
/// If the hash of the input doesn't match or no input is supplied via None,
/// it is interpreted as an error and the corresponding enum variant is set.
/// The return value signifies whether some kind of source is present.
pub fn add_external_src(&self, src: Option<String>) -> bool {
pub fn add_external_src<F>(&self, get_src: F) -> bool
where F: FnOnce() -> Option<String>
{
if *self.external_src.borrow() == ExternalSource::AbsentOk {
let src = get_src();
let mut external_src = self.external_src.borrow_mut();
if let Some(src) = src {
let mut hasher: StableHasher<u128> = StableHasher::new();
Expand Down

0 comments on commit 6807eef

Please sign in to comment.