diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-10-23 22:19:26 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-10-23 22:19:26 -0400 |
commit | e743e94e540341465175a489e82f67d3da071e77 (patch) | |
tree | cf42b8af9cfcd84019478bf8b567325535da071b /coverage/parser.py | |
parent | 9a54cb40b10ec08b5d4a6c6c88aadc5c5a343726 (diff) | |
download | python-coveragepy-e743e94e540341465175a489e82f67d3da071e77.tar.gz |
Use sets as much as possible to speed HTML reports. Seems to be a 10% speedup.
Diffstat (limited to 'coverage/parser.py')
-rw-r--r-- | coverage/parser.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index 581c851..7459eef 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -175,16 +175,18 @@ class CodeParser(object): first_line = line return first_line - def first_lines(self, lines, ignore=None): + def first_lines(self, lines, *ignores): """Map the line numbers in `lines` to the correct first line of the statement. - Skip any line mentioned in `ignore`. + Skip any line mentioned in any of the sequences in `ignores`. - Returns a sorted list of the first lines. + Returns a set of the first lines. """ - ignore = ignore or [] + ignore = set() + for ign in ignores: + ignore.update(ign) lset = set() for l in lines: if l in ignore: @@ -192,13 +194,13 @@ class CodeParser(object): new_l = self.first_line(l) if new_l not in ignore: lset.add(new_l) - return sorted(lset) + return lset def parse_source(self): """Parse source text to find executable lines, excluded lines, etc. - Return values are 1) a sorted list of executable line numbers, and - 2) a sorted list of excluded line numbers. + Return values are 1) a set of executable line numbers, and 2) a set of + excluded line numbers. Reported line numbers are normalized to the first line of multi-line statements. @@ -215,8 +217,11 @@ class CodeParser(object): ) excluded_lines = self.first_lines(self.excluded) - ignore = excluded_lines + list(self.docstrings) - lines = self.first_lines(self.statement_starts, ignore) + lines = self.first_lines( + self.statement_starts, + excluded_lines, + self.docstrings + ) return lines, excluded_lines |