Auto merge of #135371 - Mark-Simulacrum:no-alloc-case-cmp, r=compiler-errors
Remove allocations from case-insensitive comparison to keywords
Follows up on work in 99d02fb40f
, expanding the alloc-free comparisons to more cases of case-insensitive keyword matching.
r? ghost for perf
This commit is contained in:
commit
047bc17d4f
2 changed files with 5 additions and 3 deletions
|
@ -909,7 +909,8 @@ impl Token {
|
|||
self.is_keyword(kw)
|
||||
|| (case == Case::Insensitive
|
||||
&& self.is_non_raw_ident_where(|id| {
|
||||
id.name.as_str().to_lowercase() == kw.as_str().to_lowercase()
|
||||
// Do an ASCII case-insensitive match, because all keywords are ASCII.
|
||||
id.name.as_str().eq_ignore_ascii_case(kw.as_str())
|
||||
}))
|
||||
}
|
||||
|
||||
|
|
|
@ -655,9 +655,9 @@ impl<'a> Parser<'a> {
|
|||
fn check_keyword_case(&mut self, exp: ExpKeywordPair, case: Case) -> bool {
|
||||
if self.check_keyword(exp) {
|
||||
true
|
||||
// Do an ASCII case-insensitive match, because all keywords are ASCII.
|
||||
} else if case == Case::Insensitive
|
||||
&& let Some((ident, IdentIsRaw::No)) = self.token.ident()
|
||||
// Do an ASCII case-insensitive match, because all keywords are ASCII.
|
||||
&& ident.as_str().eq_ignore_ascii_case(exp.kw.as_str())
|
||||
{
|
||||
true
|
||||
|
@ -689,7 +689,8 @@ impl<'a> Parser<'a> {
|
|||
true
|
||||
} else if case == Case::Insensitive
|
||||
&& let Some((ident, IdentIsRaw::No)) = self.token.ident()
|
||||
&& ident.as_str().to_lowercase() == exp.kw.as_str().to_lowercase()
|
||||
// Do an ASCII case-insensitive match, because all keywords are ASCII.
|
||||
&& ident.as_str().eq_ignore_ascii_case(exp.kw.as_str())
|
||||
{
|
||||
self.dcx().emit_err(errors::KwBadCase { span: ident.span, kw: exp.kw.as_str() });
|
||||
self.bump();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue