mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Short circuit lex_identifier
if the name is longer or shorter than any known keyword (#13815)
This commit is contained in:
parent
6964eef369
commit
bd33b4972d
1 changed files with 8 additions and 0 deletions
|
@ -648,6 +648,14 @@ impl<'src> Lexer<'src> {
|
||||||
return TokenKind::Name;
|
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 {
|
match text {
|
||||||
"False" => TokenKind::False,
|
"False" => TokenKind::False,
|
||||||
"None" => TokenKind::None,
|
"None" => TokenKind::None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue