diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-06-03 09:21:27 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-06-05 07:43:15 +1000 |
| commit | f9209fcd634fd5fc1fc83387af3b16b7cab62b74 (patch) | |
| tree | 50e862392411e828b796b0d962dba3dad21055d4 | |
| parent | e19857c4dbbde65803d619011af4415fbdda8c01 (diff) | |
| download | rust-f9209fcd634fd5fc1fc83387af3b16b7cab62b74.tar.gz rust-f9209fcd634fd5fc1fc83387af3b16b7cab62b74.zip | |
Add and use `SyntaxContext::outer_and_expn_info`.
This combines two `HygieneData::with` calls into one on a hot path.
| -rw-r--r-- | src/librustc/ty/query/on_disk_cache.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax_pos/hygiene.rs | 10 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/librustc/ty/query/on_disk_cache.rs b/src/librustc/ty/query/on_disk_cache.rs index 24ba0744a68..4dbc2ab1b35 100644 --- a/src/librustc/ty/query/on_disk_cache.rs +++ b/src/librustc/ty/query/on_disk_cache.rs @@ -844,9 +844,8 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<Span> for CacheEncoder<'enc, 'a, 'tcx if span_data.ctxt == SyntaxContext::empty() { TAG_NO_EXPANSION_INFO.encode(self) } else { - let mark = span_data.ctxt.outer(); - - if let Some(expn_info) = mark.expn_info() { + let (mark, expn_info) = span_data.ctxt.outer_and_expn_info(); + if let Some(expn_info) = expn_info { if let Some(pos) = self.expn_info_shorthands.get(&mark).cloned() { TAG_EXPANSION_INFO_SHORTHAND.encode(self)?; pos.encode(self) diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index e50b9da62e7..5691258152a 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -565,6 +565,16 @@ impl SyntaxContext { HygieneData::with(|data| data.expn_info(data.outer(self))) } + /// `ctxt.outer_and_expn_info()` is equivalent to but faster than + /// `{ let outer = ctxt.outer(); (outer, outer.expn_info()) }`. + #[inline] + pub fn outer_and_expn_info(self) -> (Mark, Option<ExpnInfo>) { + HygieneData::with(|data| { + let outer = data.outer(self); + (outer, data.expn_info(outer)) + }) + } + pub fn dollar_crate_name(self) -> Symbol { HygieneData::with(|data| data.syntax_contexts[self.0 as usize].dollar_crate_name) } |
