mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Speed up Token::{ident,lifetime}
.
They're hot enough that the repeated matching done by `uninterpolate` has a measurable effect.
This commit is contained in:
parent
baaa3b6829
commit
637a93cb5d
@ -475,19 +475,29 @@ impl Token {
|
||||
}
|
||||
|
||||
/// Returns an identifier if this token is an identifier.
|
||||
#[inline]
|
||||
pub fn ident(&self) -> Option<(Ident, /* is_raw */ bool)> {
|
||||
let token = self.uninterpolate();
|
||||
match token.kind {
|
||||
Ident(name, is_raw) => Some((Ident::new(name, token.span), is_raw)),
|
||||
// We avoid using `Token::uninterpolate` here because it's slow.
|
||||
match &self.kind {
|
||||
&Ident(name, is_raw) => Some((Ident::new(name, self.span), is_raw)),
|
||||
Interpolated(nt) => match **nt {
|
||||
NtIdent(ident, is_raw) => Some((ident, is_raw)),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a lifetime identifier if this token is a lifetime.
|
||||
#[inline]
|
||||
pub fn lifetime(&self) -> Option<Ident> {
|
||||
let token = self.uninterpolate();
|
||||
match token.kind {
|
||||
Lifetime(name) => Some(Ident::new(name, token.span)),
|
||||
// We avoid using `Token::uninterpolate` here because it's slow.
|
||||
match &self.kind {
|
||||
&Lifetime(name) => Some(Ident::new(name, self.span)),
|
||||
Interpolated(nt) => match **nt {
|
||||
NtLifetime(ident) => Some(ident),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user