diff options
author | Ian Cordasco <sigmavirus24@users.noreply.github.com> | 2017-05-14 10:23:03 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-14 10:23:03 -0500 |
commit | 727dc51ed5f47e2ade2869f0d994fa8410e6b8c1 (patch) | |
tree | d0485f78a9564c3830fdb3940fc5a13a7073b0a8 | |
parent | 54a11aa5b8aec78d29048093cf1e8d3af6819ad2 (diff) | |
parent | 83782f6cb617ef10186af270c05bfc87a4b4d0bb (diff) | |
download | pep8-727dc51ed5f47e2ade2869f0d994fa8410e6b8c1.tar.gz |
Merge pull request #648 from JulienPalard/bisect
Use bisect instead of iterating over every offsets.
-rwxr-xr-x | pycodestyle.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/pycodestyle.py b/pycodestyle.py index 2e03301..763747e 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -56,6 +56,7 @@ import sys import time import tokenize import warnings +import bisect from fnmatch import fnmatch from optparse import OptionParser @@ -1664,10 +1665,10 @@ class Checker(object): """Build a line from tokens and run all logical checks on it.""" self.report.increment_logical_line() mapping = self.build_tokens_line() - if not mapping: return + mapping_offsets = [offset for offset, _ in mapping] (start_row, start_col) = mapping[0][1] start_line = self.lines[start_row - 1] self.indent_level = expand_indent(start_line[:start_col]) @@ -1681,9 +1682,10 @@ class Checker(object): self.init_checker_state(name, argument_names) for offset, text in self.run_check(check, argument_names) or (): if not isinstance(offset, tuple): - for token_offset, pos in mapping: - if offset <= token_offset: - break + # As mappings are ordered, bisecting is a fast way + # to find a given offset in them. + token_offset, pos = mapping[bisect.bisect_left( + mapping_offsets, offset)] offset = (pos[0], pos[1] + offset - token_offset) self.report_error(offset[0], offset[1], text, check) if self.logical_line: |