Skip to content

Commit

Permalink
Recognize underscore token to avoid slow path
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 27, 2021
1 parent 21f1da1 commit 53109e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Expand Up @@ -1074,6 +1074,10 @@ macro_rules! quote_token {
$crate::__private::push_literal(&mut $tokens, stringify!($literal));
};

($tokens:ident _) => {
$crate::__private::push_underscore(&mut $tokens);
};

($tokens:ident $other:tt) => {
$crate::__private::parse(&mut $tokens, stringify!($other));
};
Expand Down Expand Up @@ -1297,6 +1301,10 @@ macro_rules! quote_token_spanned {
$crate::__private::push_literal_spanned(&mut $tokens, $span, stringify!($literal));
};

($tokens:ident $span:ident _) => {
$crate::__private::push_underscore_spanned(&mut $tokens, $span);
};

($tokens:ident $span:ident $other:tt) => {
$crate::__private::parse_spanned(&mut $tokens, $span, stringify!($other));
};
Expand Down
8 changes: 8 additions & 0 deletions src/runtime.rs
Expand Up @@ -396,6 +396,14 @@ push_punct!(push_star push_star_spanned '*');
push_punct!(push_sub push_sub_spanned '-');
push_punct!(push_sub_eq push_sub_eq_spanned '-' '=');

pub fn push_underscore(tokens: &mut TokenStream) {
push_underscore_spanned(tokens, Span::call_site());
}

pub fn push_underscore_spanned(tokens: &mut TokenStream, span: Span) {
tokens.append(Ident::new("_", span));
}

// Helper method for constructing identifiers from the `format_ident!` macro,
// handling `r#` prefixes.
//
Expand Down

0 comments on commit 53109e8

Please sign in to comment.