Refactor loop to only calculate the full_path once

This commit is contained in:
Toshio Kuratomi 2015-02-26 16:01:42 -08:00
parent 68c99a12b3
commit 0f4b72cdfa

View file

@ -176,19 +176,18 @@ class PluginLoader(object):
found = None found = None
for path in [p for p in self._get_paths() if p not in self._searched_paths]: for path in [p for p in self._get_paths() if p not in self._searched_paths]:
if os.path.isdir(path): if os.path.isdir(path):
for potential_file in (f for f in os.listdir(path) full_paths = (os.path.join(path, f) for f in os.listdir(path))
if os.path.isfile(os.path.join(path, f))): for full_path in (f for f in full_paths if os.path.isfile(f)):
for suffix in suffixes: for suffix in suffixes:
if potential_file.endswith(suffix): if full_path.endswith(suffix):
full_path = os.path.join(path, potential_file)
full_name = os.path.basename(full_path) full_name = os.path.basename(full_path)
break break
else: # Yes, this is a for-else: http://bit.ly/1ElPkyg else: # Yes, this is a for-else: http://bit.ly/1ElPkyg
continue continue
if full_name not in self._plugin_path_cache: if full_name not in self._plugin_path_cache:
self._plugin_path_cache[full_name] = full_path self._plugin_path_cache[full_name] = full_path
self._searched_paths.add(path) self._searched_paths.add(path)
for full_name in potential_names: for full_name in potential_names:
if full_name in self._plugin_path_cache: if full_name in self._plugin_path_cache: