Skip to content

Commit f9209fc

Browse files
committed
Add and use SyntaxContext::outer_and_expn_info.
This combines two `HygieneData::with` calls into one on a hot path.
1 parent e19857c commit f9209fc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/librustc/ty/query/on_disk_cache.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -844,9 +844,8 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<Span> for CacheEncoder<'enc, 'a, 'tcx
844844
if span_data.ctxt == SyntaxContext::empty() {
845845
TAG_NO_EXPANSION_INFO.encode(self)
846846
} else {
847-
let mark = span_data.ctxt.outer();
848-
849-
if let Some(expn_info) = mark.expn_info() {
847+
let (mark, expn_info) = span_data.ctxt.outer_and_expn_info();
848+
if let Some(expn_info) = expn_info {
850849
if let Some(pos) = self.expn_info_shorthands.get(&mark).cloned() {
851850
TAG_EXPANSION_INFO_SHORTHAND.encode(self)?;
852851
pos.encode(self)

src/libsyntax_pos/hygiene.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,16 @@ impl SyntaxContext {
565565
HygieneData::with(|data| data.expn_info(data.outer(self)))
566566
}
567567

568+
/// `ctxt.outer_and_expn_info()` is equivalent to but faster than
569+
/// `{ let outer = ctxt.outer(); (outer, outer.expn_info()) }`.
570+
#[inline]
571+
pub fn outer_and_expn_info(self) -> (Mark, Option<ExpnInfo>) {
572+
HygieneData::with(|data| {
573+
let outer = data.outer(self);
574+
(outer, data.expn_info(outer))
575+
})
576+
}
577+
568578
pub fn dollar_crate_name(self) -> Symbol {
569579
HygieneData::with(|data| data.syntax_contexts[self.0 as usize].dollar_crate_name)
570580
}

0 commit comments

Comments
 (0)