diff options
| author | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-08-01 14:17:11 +0300 |
|---|---|---|
| committer | Ariel Ben-Yehuda <ariel.byd@gmail.com> | 2017-08-01 14:18:49 +0300 |
| commit | c9d14a846f4e34d2cf0db89423a32428ad8e924f (patch) | |
| tree | 1f14abe3ead139fc94cf7507421a17e5d18940ba /src/libsyntax_pos | |
| parent | 91aff5775d3b4a95e2b0c2fe50785f3d28fa3dd8 (diff) | |
| download | rust-c9d14a846f4e34d2cf0db89423a32428ad8e924f.tar.gz rust-c9d14a846f4e34d2cf0db89423a32428ad8e924f.zip | |
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.
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 3a701f91314..7006f45455e 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -618,8 +618,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(); |
