ruff
9781563e - Add fast-path for comment detection (#9808)

Comment changes are shownComment changes are hidden
Commit
1 year ago
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).
Author
Parents
  • crates
    • ruff_linter/src/rules/eradicate
      • File
        detection.rs
    • ruff_python_trivia/src
      • snapshots
        • ruff_python_trivia__tokenizer__tests__identifier_ending_in_non_start_char.snap
        • ruff_python_trivia__tokenizer__tests__identifier_starting_with_string_kind.snap
        • ruff_python_trivia__tokenizer__tests__string_with_byte_kind.snap
        • ruff_python_trivia__tokenizer__tests__string_with_invalid_kind.snap
        • ruff_python_trivia__tokenizer__tests__string_with_kind.snap
        • ruff_python_trivia__tokenizer__tests__tricky_unicode.snap
      • File
        tokenizer.rs