diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-11-07 16:09:39 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-11-13 08:43:47 +1100 |
| commit | 99d02fb40fd339255ed08596ebeb41e9b8a09d45 (patch) | |
| tree | 3ebe2f9443ca8b246449f7831749063db4ef46a0 | |
| parent | f7273e0044ad8f35ad27282e4ab776af50b61a54 (diff) | |
| download | rust-99d02fb40fd339255ed08596ebeb41e9b8a09d45.tar.gz rust-99d02fb40fd339255ed08596ebeb41e9b8a09d45.zip | |
Optimize `check_keyword_case`.
`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.
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 50a8b6542df..042ee96bbe8 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -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 { |
