1
Fork 0

Refactor SyntaxContext::ctxt logic.

This commit is contained in:
Camille GILLOT 2023-04-18 17:54:34 +00:00
parent de96f3d873
commit 99962a8418

View file

@ -181,19 +181,23 @@ impl Span {
#[inline] #[inline]
pub fn ctxt(self) -> SyntaxContext { pub fn ctxt(self) -> SyntaxContext {
let ctxt_or_tag = self.ctxt_or_tag as u32; let ctxt_or_tag = self.ctxt_or_tag as u32;
if ctxt_or_tag <= MAX_CTXT { // Check for interned format.
if self.len_or_tag == LEN_TAG || self.len_or_tag & PARENT_MASK == 0 { if self.len_or_tag == LEN_TAG {
// Inline format or interned format with inline ctxt. if ctxt_or_tag == CTXT_TAG {
SyntaxContext::from_u32(ctxt_or_tag) // Fully interned format.
let index = self.base_or_index;
with_span_interner(|interner| interner.spans[index as usize].ctxt)
} else { } else {
// Inline format or interned format with inline parent. // Interned format with inline ctxt.
// We know that the SyntaxContext is root. SyntaxContext::from_u32(ctxt_or_tag)
SyntaxContext::root()
} }
} else if self.len_or_tag & PARENT_MASK == 0 {
// Inline format with inline ctxt.
SyntaxContext::from_u32(ctxt_or_tag)
} else { } else {
// Interned format. // Inline format with inline parent.
let index = self.base_or_index; // We know that the SyntaxContext is root.
with_span_interner(|interner| interner.spans[index as usize].ctxt) SyntaxContext::root()
} }
} }
} }