Skip to content

Commit aa4f879

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 4dbecdb commit aa4f879

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
@@ -161,8 +161,8 @@ class EntryPoint(DeprecatedTuple):
161161

162162
pattern = re.compile(
163163
r'(?P<module>[\w.]+)\s*'
164-
r'(:\s*(?P<attr>[\w.]+))?\s*'
165-
r'(?P<extras>\[.*\])?\s*$'
164+
r'(:\s*(?P<attr>[\w.]+)\s*)?'
165+
r'((?P<extras>\[.*\])\s*)?$'
166166
)
167167
"""
168168
A regular expression describing the syntax for an entry point,

0 commit comments

Comments
 (0)