Short circuit lex_identifier if the name is longer or shorter than any known keyword (#13815)

This commit is contained in:
Micha Reiser 2024-10-19 13:07:15 +02:00 committed by GitHub
parent 6964eef369
commit bd33b4972d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -648,6 +648,14 @@ impl<'src> Lexer<'src> {
return TokenKind::Name;
}
// Short circuit for names that are longer than any known keyword.
// It helps Rust to predict that the Name::new call in the keyword match's default branch
// is guaranteed to fit into a stack allocated (inline) Name.
if text.len() > 8 {
self.current_value = TokenValue::Name(Name::new(text));
return TokenKind::Name;
}
match text {
"False" => TokenKind::False,
"None" => TokenKind::None,