diff options
author | Marius Gedminas <marius@gedmin.as> | 2018-11-22 15:17:40 +0200 |
---|---|---|
committer | Marius Gedminas <marius@gedmin.as> | 2018-11-22 15:17:40 +0200 |
commit | e5a057982bfd68cd825eeea6bd8dce5bc0759e9f (patch) | |
tree | c10b7d716fa2fb483a2173c8c0a8fe98dac1389c | |
parent | cb8402add912fa162a42eef9067c446704d919d3 (diff) | |
download | pep8-e5a057982bfd68cd825eeea6bd8dce5bc0759e9f.tar.gz |
Microoptimisation: avoid creating string slices
str.count() can limit the counting to a range of string positions.
-rwxr-xr-x | pycodestyle.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pycodestyle.py b/pycodestyle.py index 5b66302..f0ae6dc 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1535,7 +1535,7 @@ def python_3000_invalid_escape_sequence(logical_line, tokens): while pos >= 0: pos += 1 if string[pos] not in valid: - line = start_line + string[:pos].count('\n') + line = start_line + string.count('\n', 0, pos) if line == start_line: col = start_col + len(prefix) + len(quote) + pos else: |