mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-09 18:03:03 +00:00
Add an explicit fast path for whitespace to is_identifier_continuation
(#9532)
This commit is contained in:
parent
2b605527bd
commit
21f2d0c90b
3 changed files with 14 additions and 6 deletions
|
@ -1498,9 +1498,12 @@ fn is_unicode_identifier_start(c: char) -> bool {
|
||||||
// Checks if the character c is a valid continuation character as described
|
// Checks if the character c is a valid continuation character as described
|
||||||
// in https://docs.python.org/3/reference/lexical_analysis.html#identifiers
|
// in https://docs.python.org/3/reference/lexical_analysis.html#identifiers
|
||||||
fn is_identifier_continuation(c: char) -> bool {
|
fn is_identifier_continuation(c: char) -> bool {
|
||||||
match c {
|
// Arrange things such that ASCII codepoints never
|
||||||
'a'..='z' | 'A'..='Z' | '_' | '0'..='9' => true,
|
// result in the slower `is_xid_continue` getting called.
|
||||||
c => is_xid_continue(c),
|
if c.is_ascii() {
|
||||||
|
matches!(c, 'a'..='z' | 'A'..='Z' | '_' | '0'..='9')
|
||||||
|
} else {
|
||||||
|
is_xid_continue(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,12 @@ fn is_identifier_start(c: char) -> bool {
|
||||||
// Checks if the character c is a valid continuation character as described
|
// Checks if the character c is a valid continuation character as described
|
||||||
// in https://docs.python.org/3/reference/lexical_analysis.html#identifiers
|
// in https://docs.python.org/3/reference/lexical_analysis.html#identifiers
|
||||||
fn is_identifier_continuation(c: char) -> bool {
|
fn is_identifier_continuation(c: char) -> bool {
|
||||||
match c {
|
// Arrange things such that ASCII codepoints never
|
||||||
'a'..='z' | 'A'..='Z' | '_' | '0'..='9' => true,
|
// result in the slower `is_xid_continue` getting called.
|
||||||
c => is_xid_continue(c),
|
if c.is_ascii() {
|
||||||
|
matches!(c, 'a'..='z' | 'A'..='Z' | '_' | '0'..='9')
|
||||||
|
} else {
|
||||||
|
is_xid_continue(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,8 @@ fn is_identifier_start(c: char) -> bool {
|
||||||
// Checks if the character c is a valid continuation character as described
|
// Checks if the character c is a valid continuation character as described
|
||||||
// in https://docs.python.org/3/reference/lexical_analysis.html#identifiers
|
// in https://docs.python.org/3/reference/lexical_analysis.html#identifiers
|
||||||
fn is_identifier_continuation(c: char) -> bool {
|
fn is_identifier_continuation(c: char) -> bool {
|
||||||
|
// Arrange things such that ASCII codepoints never
|
||||||
|
// result in the slower `is_xid_continue` getting called.
|
||||||
if c.is_ascii() {
|
if c.is_ascii() {
|
||||||
matches!(c, 'a'..='z' | 'A'..='Z' | '_' | '0'..='9')
|
matches!(c, 'a'..='z' | 'A'..='Z' | '_' | '0'..='9')
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue