Skip to content

Commit

Permalink
refactor: no need to compile a regex used once
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Aug 24, 2024
1 parent bfb0c70 commit 468aa22
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions coverage/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ def lines_matching(self, regex: str) -> set[TLineNo]:
Handles multiline regex patterns.
"""
regex_c = re.compile(regex, re.MULTILINE)
matches: set[TLineNo] = set()

last_start = 0
last_start_line = 0
for match in regex_c.finditer(self.text):
for match in re.finditer(regex, self.text, flags=re.MULTILINE):
start, end = match.span()
start_line = last_start_line + self.text.count('\n', last_start, start)
end_line = last_start_line + self.text.count('\n', last_start, end)
Expand Down

0 comments on commit 468aa22

Please sign in to comment.