Auto merge of #126543 - petrochenkov:upctxt4, r=cjgillot

rustc_span: Optimize more hygiene operations using `Span::map_ctxt`

I missed these in https://github.com/rust-lang/rust/pull/125017.
This commit is contained in:
bors 2024-06-16 23:34:12 +00:00
commit 6b65c30f8e

View File

@ -1065,33 +1065,41 @@ pub fn apply_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span {
#[inline] #[inline]
pub fn remove_mark(&mut self) -> ExpnId { pub fn remove_mark(&mut self) -> ExpnId {
let mut span = self.data(); let mut mark = ExpnId::root();
let mark = span.ctxt.remove_mark(); *self = self.map_ctxt(|mut ctxt| {
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent); mark = ctxt.remove_mark();
ctxt
});
mark mark
} }
#[inline] #[inline]
pub fn adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> { pub fn adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
let mut span = self.data(); let mut mark = None;
let mark = span.ctxt.adjust(expn_id); *self = self.map_ctxt(|mut ctxt| {
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent); mark = ctxt.adjust(expn_id);
ctxt
});
mark mark
} }
#[inline] #[inline]
pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> { pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
let mut span = self.data(); let mut mark = None;
let mark = span.ctxt.normalize_to_macros_2_0_and_adjust(expn_id); *self = self.map_ctxt(|mut ctxt| {
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent); mark = ctxt.normalize_to_macros_2_0_and_adjust(expn_id);
ctxt
});
mark mark
} }
#[inline] #[inline]
pub fn glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> { pub fn glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> {
let mut span = self.data(); let mut mark = None;
let mark = span.ctxt.glob_adjust(expn_id, glob_span); *self = self.map_ctxt(|mut ctxt| {
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent); mark = ctxt.glob_adjust(expn_id, glob_span);
ctxt
});
mark mark
} }
@ -1101,9 +1109,11 @@ pub fn reverse_glob_adjust(
expn_id: ExpnId, expn_id: ExpnId,
glob_span: Span, glob_span: Span,
) -> Option<Option<ExpnId>> { ) -> Option<Option<ExpnId>> {
let mut span = self.data(); let mut mark = None;
let mark = span.ctxt.reverse_glob_adjust(expn_id, glob_span); *self = self.map_ctxt(|mut ctxt| {
*self = Span::new(span.lo, span.hi, span.ctxt, span.parent); mark = ctxt.reverse_glob_adjust(expn_id, glob_span);
ctxt
});
mark mark
} }