@@ -475,19 +475,29 @@ impl Token {
475
475
}
476
476
477
477
/// Returns an identifier if this token is an identifier.
478
+ #[ inline]
478
479
pub fn ident ( & self ) -> Option < ( Ident , /* is_raw */ bool ) > {
479
- let token = self . uninterpolate ( ) ;
480
- match token. kind {
481
- Ident ( name, is_raw) => Some ( ( Ident :: new ( name, token. span ) , is_raw) ) ,
480
+ // We avoid using `Token::uninterpolate` here because it's slow.
481
+ match & self . kind {
482
+ & Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
483
+ Interpolated ( nt) => match * * nt {
484
+ NtIdent ( ident, is_raw) => Some ( ( ident, is_raw) ) ,
485
+ _ => None ,
486
+ } ,
482
487
_ => None ,
483
488
}
484
489
}
485
490
486
491
/// Returns a lifetime identifier if this token is a lifetime.
492
+ #[ inline]
487
493
pub fn lifetime ( & self ) -> Option < Ident > {
488
- let token = self . uninterpolate ( ) ;
489
- match token. kind {
490
- Lifetime ( name) => Some ( Ident :: new ( name, token. span ) ) ,
494
+ // We avoid using `Token::uninterpolate` here because it's slow.
495
+ match & self . kind {
496
+ & Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
497
+ Interpolated ( nt) => match * * nt {
498
+ NtLifetime ( ident) => Some ( ident) ,
499
+ _ => None ,
500
+ } ,
491
501
_ => None ,
492
502
}
493
503
}
@@ -521,7 +531,7 @@ impl Token {
521
531
/// (which happens while parsing the result of macro expansion)?
522
532
pub fn is_whole_expr ( & self ) -> bool {
523
533
if let Interpolated ( ref nt) = self . kind
524
- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtIdent ( .. ) | NtBlock ( _) = * * nt
534
+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
525
535
{
526
536
return true ;
527
537
}
0 commit comments