Add and use SyntaxContext::outer_and_expn_info.

This combines two `HygieneData::with` calls into one on a hot path.
This commit is contained in:
Nicholas Nethercote 2019-06-03 09:21:27 +10:00
parent e19857c4db
commit f9209fcd63
2 changed files with 12 additions and 3 deletions

View File

@ -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)

View File

@ -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)
}