Skip to content

Commit

Permalink
use list comprehension for better perf
Browse files Browse the repository at this point in the history
  • Loading branch information
youben11 committed Nov 15, 2019
1 parent b82ff8f commit 107c431
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pyls/plugins/importmagic_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def _tokenize(source):
Returns only NAME tokens.
"""
readline = _SourceReader(source).readline
filter_name = lambda token: token[0] == tokenize.NAME
return filter(filter_name, tokenize.generate_tokens(readline))
return [token for token in tokenize.generate_tokens(readline) if token[0] == tokenize.NAME]


def _search_symbol(source, symbol):
Expand All @@ -105,12 +104,11 @@ def _search_symbol(source, symbol):
}
}
"""
symbol_tokens = list(_tokenize(symbol))
source_tokens = list(_tokenize(source))
symbol_tokens = _tokenize(symbol)
source_tokens = _tokenize(source)

get_str = lambda token: token[1]
symbol_tokens_str = list(map(get_str, symbol_tokens))
source_tokens_str = list(map(get_str, source_tokens))
symbol_tokens_str = [token[1] for token in symbol_tokens]
source_tokens_str = [token[1] for token in source_tokens]

symbol_len = len(symbol_tokens)
locations = []
Expand Down

0 comments on commit 107c431

Please sign in to comment.