-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fast-path for comment detection (#9808)
## Summary When we fall through to parsing, the comment-detection rule is a significant portion of lint time. This PR adds an additional fast heuristic whereby we abort if a comment contains two consecutive name tokens (via the zero-allocation lexer). For the `ctypeslib.py`, which has a few cases that are now caught by this, it's a 2.5x speedup for the rule (and a 20% speedup for token-based rules).
- Loading branch information
1 parent
84aea7f
commit 9781563
Showing
8 changed files
with
157 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ expression: test_case.tokens() | |
--- | ||
[ | ||
SimpleToken { | ||
kind: Other, | ||
kind: Name, | ||
range: 0..2, | ||
}, | ||
] |
18 changes: 18 additions & 0 deletions
18
...snapshots/ruff_python_trivia__tokenizer__tests__identifier_starting_with_string_kind.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
source: crates/ruff_python_trivia/src/tokenizer.rs | ||
expression: test_case.tokens() | ||
--- | ||
[ | ||
SimpleToken { | ||
kind: Name, | ||
range: 0..3, | ||
}, | ||
SimpleToken { | ||
kind: Whitespace, | ||
range: 3..4, | ||
}, | ||
SimpleToken { | ||
kind: Name, | ||
range: 4..7, | ||
}, | ||
] |
14 changes: 14 additions & 0 deletions
14
...hon_trivia/src/snapshots/ruff_python_trivia__tokenizer__tests__string_with_byte_kind.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
source: crates/ruff_python_trivia/src/tokenizer.rs | ||
expression: test_case.tokens() | ||
--- | ||
[ | ||
SimpleToken { | ||
kind: Other, | ||
range: 0..2, | ||
}, | ||
SimpleToken { | ||
kind: Bogus, | ||
range: 2..7, | ||
}, | ||
] |
18 changes: 18 additions & 0 deletions
18
..._trivia/src/snapshots/ruff_python_trivia__tokenizer__tests__string_with_invalid_kind.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
source: crates/ruff_python_trivia/src/tokenizer.rs | ||
expression: test_case.tokens() | ||
--- | ||
[ | ||
SimpleToken { | ||
kind: Name, | ||
range: 0..3, | ||
}, | ||
SimpleToken { | ||
kind: Other, | ||
range: 3..4, | ||
}, | ||
SimpleToken { | ||
kind: Bogus, | ||
range: 4..8, | ||
}, | ||
] |
14 changes: 14 additions & 0 deletions
14
...f_python_trivia/src/snapshots/ruff_python_trivia__tokenizer__tests__string_with_kind.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
source: crates/ruff_python_trivia/src/tokenizer.rs | ||
expression: test_case.tokens() | ||
--- | ||
[ | ||
SimpleToken { | ||
kind: Other, | ||
range: 0..1, | ||
}, | ||
SimpleToken { | ||
kind: Bogus, | ||
range: 1..6, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ expression: test_case.tokens() | |
--- | ||
[ | ||
SimpleToken { | ||
kind: Other, | ||
kind: Name, | ||
range: 0..6, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters