mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-18 01:44:04 +00:00
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:
parent
e19857c4db
commit
f9209fcd63
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user