Skip to content

Commit cf7fef7

Browse files
committed
Refactor regular expression to avoid expensive backtracking on contrived 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.
1 parent 046bf48 commit cf7fef7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

importlib_metadata/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class EntryPoint(
7777

7878
pattern = re.compile(
7979
r'(?P<module>[\w.]+)\s*'
80-
r'(:\s*(?P<attr>[\w.]+))?\s*'
81-
r'(?P<extras>\[.*\])?\s*$'
80+
r'(:\s*(?P<attr>[\w.]+)\s*)?'
81+
r'((?P<extras>\[.*\])\s*)?$'
8282
)
8383
"""
8484
A regular expression describing the syntax for an entry point,

0 commit comments

Comments
 (0)