ruff/crates/ruff_python_ast/src
Charlie Marsh ea1c089652
Use `AhoCorasick` to speed up quote match (#9773)
<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

When I was looking at the v0.2.0 release, this method showed up in a
CodSpeed regression (we were calling it more), so I decided to quickly
look at speeding it up. @BurntSushi suggested using Aho-Corasick, and it
looks like it's about 7 or 8x faster:

```text
Parser/AhoCorasick      time:   [8.5646 ns 8.5914 ns 8.6191 ns]
Parser/Iterator         time:   [64.992 ns 65.124 ns 65.271 ns]
```

## Test Plan

`cargo test`
2024-02-02 09:57:39 -05:00
..
visitor Range formatting API (#9635) 2024-01-31 11:13:37 +01:00
all.rs Misc. small tweaks from perusing modules (#9383) 2024-01-03 12:30:25 -05:00
call_path.rs Store call paths rather than stringified names (#6102) 2023-08-05 15:21:50 +00:00
comparable.rs Add `as_slice` method for all string nodes (#9111) 2023-12-13 06:31:20 +00:00
docstrings.rs Move Python whitespace utilities into new `ruff_python_whitespace` crate (#4993) 2023-06-10 00:59:57 +00:00
expression.rs Introduce `StringLike` enum (#9016) 2023-12-07 16:39:13 +00:00
hashable.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
helpers.rs [`ruff`] Avoid treating named expressions as static keys (`RUF011`) (#9494) 2024-01-12 14:33:45 -05:00
identifier.rs Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
imports.rs Use Rust 1.75 toolchain (#9437) 2024-01-08 18:03:16 +01:00
int.rs Include radix base prefix in large number representation (#7700) 2023-09-28 20:38:06 +00:00
lib.rs Update `E402` to work at cell level for notebooks (#8872) 2023-11-29 00:32:35 +00:00
node.rs Range formatting API (#9635) 2024-01-31 11:13:37 +01:00
nodes.rs Move `is_tuple_parenthesized` from the formatter to `ruff_python_ast` (#9533) 2024-01-15 16:10:40 +00:00
parenthesize.rs Comments outside expression parentheses (#7873) 2023-10-19 09:24:11 +00:00
relocate.rs New AST nodes for f-string elements (#8835) 2023-12-07 10:28:05 -06:00
statement_visitor.rs Remove `Stmt::TryStar` (#6566) 2023-08-14 13:39:44 -04:00
stmt_if.rs Misc. small tweaks from perusing modules (#9383) 2024-01-03 12:30:25 -05:00
str.rs Use `AhoCorasick` to speed up quote match (#9773) 2024-02-02 09:57:39 -05:00
traversal.rs [`flake8-simplify`] Implement `enumerate-for-loop` (`SIM113`) (#7777) 2024-01-14 11:00:59 -05:00
types.rs Remove `RefEquality` (#6393) 2023-08-07 16:04:50 +00:00
visitor.rs Add `as_slice` method for all string nodes (#9111) 2023-12-13 06:31:20 +00:00
whitespace.rs Use consistent re-export from `ruff_source_file` (#9320) 2023-12-30 14:48:45 -05:00