Skip to content

Commit

Permalink
Refactor regular expression to avoid expensive backtracking on contri…
Browse files Browse the repository at this point in the history
…ved entry points.

Fixes #361.

Credit to Tim Peters.

Reduces cost from almost 2 seconds to ~100 µs on my workstation as reported by entrypoint_regexp_perf.
  • Loading branch information
jaraco committed Jan 17, 2022
1 parent 4dbecdb commit aa4f879
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class EntryPoint(DeprecatedTuple):

pattern = re.compile(
r'(?P<module>[\w.]+)\s*'
r'(:\s*(?P<attr>[\w.]+))?\s*'
r'(?P<extras>\[.*\])?\s*$'
r'(:\s*(?P<attr>[\w.]+)\s*)?'
r'((?P<extras>\[.*\])\s*)?$'
)
"""
A regular expression describing the syntax for an entry point,
Expand Down

0 comments on commit aa4f879

Please sign in to comment.