Skip to content

Commit

Permalink
Optimize check_keyword_case.
Browse files Browse the repository at this point in the history
`to_lowercase` allocates, but `eq_ignore_ascii_case` doesn't. This path
is hot enough that this makes a small but noticeable difference in
benchmarking.
  • Loading branch information
nnethercote committed Nov 12, 2024
1 parent f7273e0 commit 99d02fb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,10 @@ impl<'a> Parser<'a> {
return true;
}

// Do an ASCII case-insensitive match, because all keywords are ASCII.
if case == Case::Insensitive
&& let Some((ident, IdentIsRaw::No)) = self.token.ident()
&& ident.as_str().to_lowercase() == kw.as_str().to_lowercase()
&& ident.as_str().eq_ignore_ascii_case(kw.as_str())
{
true
} else {
Expand Down

0 comments on commit 99d02fb

Please sign in to comment.