Add an explicit fast path for whitespace to is_identifier_continuation (#9532)

This commit is contained in:
Micha Reiser 2024-01-16 09:23:43 +01:00 committed by GitHub
parent 2b605527bd
commit 21f2d0c90b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View file

@ -1498,9 +1498,12 @@ fn is_unicode_identifier_start(c: char) -> bool {
// Checks if the character c is a valid continuation character as described
// in https://docs.python.org/3/reference/lexical_analysis.html#identifiers
fn is_identifier_continuation(c: char) -> bool {
match c {
'a'..='z' | 'A'..='Z' | '_' | '0'..='9' => true,
c => is_xid_continue(c),
// Arrange things such that ASCII codepoints never
// result in the slower `is_xid_continue` getting called.
if c.is_ascii() {
matches!(c, 'a'..='z' | 'A'..='Z' | '_' | '0'..='9')
} else {
is_xid_continue(c)
}
}