mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
Fast path for ASCII only identifiers start (#6609)
This commit is contained in:
parent
2d86e78bfc
commit
e28858bb29
2 changed files with 21 additions and 14 deletions
|
@ -50,17 +50,24 @@ where
|
|||
|
||||
let node_comments = comments.leading_dangling_trailing_comments(node.as_any_node_ref());
|
||||
|
||||
leading_comments(node_comments.leading).fmt(f)?;
|
||||
self.fmt_node(node, f)?;
|
||||
self.fmt_dangling_comments(node_comments.dangling, f)?;
|
||||
trailing_comments(node_comments.trailing).fmt(f)
|
||||
}
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
leading_comments(node_comments.leading),
|
||||
source_position(node.start())
|
||||
]
|
||||
)?;
|
||||
|
||||
/// Formats the node without comments. Ignores any suppression comments.
|
||||
fn fmt_node(&self, node: &N, f: &mut PyFormatter) -> FormatResult<()> {
|
||||
write!(f, [source_position(node.start())])?;
|
||||
self.fmt_fields(node, f)?;
|
||||
write!(f, [source_position(node.end())])
|
||||
self.fmt_dangling_comments(node_comments.dangling, f)?;
|
||||
|
||||
write!(
|
||||
f,
|
||||
[
|
||||
source_position(node.end()),
|
||||
trailing_comments(node_comments.trailing)
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
/// Formats the node's fields.
|
||||
|
|
|
@ -85,7 +85,11 @@ pub fn lines_after_ignoring_trivia(offset: TextSize, code: &str) -> u32 {
|
|||
}
|
||||
|
||||
fn is_identifier_start(c: char) -> bool {
|
||||
c.is_ascii_alphabetic() || c == '_' || is_non_ascii_identifier_start(c)
|
||||
if c.is_ascii() {
|
||||
c.is_ascii_alphabetic() || c == '_'
|
||||
} else {
|
||||
is_xid_start(c)
|
||||
}
|
||||
}
|
||||
|
||||
// Checks if the character c is a valid continuation character as described
|
||||
|
@ -98,10 +102,6 @@ fn is_identifier_continuation(c: char) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_non_ascii_identifier_start(c: char) -> bool {
|
||||
is_xid_start(c)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
||||
pub struct SimpleToken {
|
||||
pub kind: SimpleTokenKind,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue