ruff/crates/ruff_python_stdlib/src
Charlie Marsh d0ad1ed0af
Replace static CallPath vectors with matches! macros (#5148)
## Summary

After #5140, I audited the codebase for similar patterns (defining a
list of `CallPath` entities in a static vector, then looping over them
to pattern-match). This PR migrates all other such cases to use `match`
and `matches!` where possible.

There are a few benefits to this:

1. It more clearly denotes the intended semantics (branches are
exclusive).
2. The compiler can help deduplicate the patterns and detect unreachable
branches.
3. Performance: in the benchmark below, the all-rules performance is
increased by nearly 10%...

## Benchmarks

I decided to benchmark against a large file in the Airflow repository
with a lot of type annotations
([`views.py`](https://raw.githubusercontent.com/apache/airflow/f03f73100e8a7d6019249889de567cb00e71e457/airflow/www/views.py)):

```
linter/default-rules/airflow/views.py
                        time:   [10.871 ms 10.882 ms 10.894 ms]
                        thrpt:  [19.739 MiB/s 19.761 MiB/s 19.781 MiB/s]
                 change:
                        time:   [-2.7182% -2.5687% -2.4204%] (p = 0.00 < 0.05)
                        thrpt:  [+2.4805% +2.6364% +2.7942%]
                        Performance has improved.

linter/all-rules/airflow/views.py
                        time:   [24.021 ms 24.038 ms 24.062 ms]
                        thrpt:  [8.9373 MiB/s 8.9461 MiB/s 8.9527 MiB/s]
                 change:
                        time:   [-8.9537% -8.8516% -8.7527%] (p = 0.00 < 0.05)
                        thrpt:  [+9.5923% +9.7112% +9.8342%]
                        Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
  5 (5.00%) high mild
  7 (7.00%) high severe
```

The impact is dramatic -- nearly a 10% improvement for `all-rules`.
2023-06-16 17:34:42 +00:00
..
builtins.rs Rename ruff_python crate to ruff_python_stdlib (#3354) 2023-03-06 13:43:22 +00:00
future.rs Rename ruff_python crate to ruff_python_stdlib (#3354) 2023-03-06 13:43:22 +00:00
identifiers.rs Move keyword checks into is_identifier (#3834) 2023-03-31 16:56:33 -04:00
keyword.rs Move keyword checks into is_identifier (#3834) 2023-03-31 16:56:33 -04:00
lib.rs Introduce a ruff_python_semantic crate (#3865) 2023-04-04 16:50:47 +00:00
logging.rs Introduce a ruff_python_semantic crate (#3865) 2023-04-04 16:50:47 +00:00
path.rs Lint pyproject.toml (#4496) 2023-05-25 12:05:28 +00:00
str.rs Avoid allocations in lowercase comparisons (#5137) 2023-06-16 08:57:43 -04:00
sys.rs Rename ruff_python crate to ruff_python_stdlib (#3354) 2023-03-06 13:43:22 +00:00
typing.rs Replace static CallPath vectors with matches! macros (#5148) 2023-06-16 17:34:42 +00:00