From 0f4b72cdfa0b5a05dc6cffddb7c4e54bcfaa49a7 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 26 Feb 2015 16:01:42 -0800 Subject: [PATCH] Refactor loop to only calculate the full_path once --- lib/ansible/utils/plugins.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/ansible/utils/plugins.py b/lib/ansible/utils/plugins.py index 3deef4d3c28..eccf2988557 100644 --- a/lib/ansible/utils/plugins.py +++ b/lib/ansible/utils/plugins.py @@ -176,19 +176,18 @@ class PluginLoader(object): found = None for path in [p for p in self._get_paths() if p not in self._searched_paths]: if os.path.isdir(path): - for potential_file in (f for f in os.listdir(path) - if os.path.isfile(os.path.join(path, f))): + full_paths = (os.path.join(path, f) for f in os.listdir(path)) + for full_path in (f for f in full_paths if os.path.isfile(f)): for suffix in suffixes: - if potential_file.endswith(suffix): - full_path = os.path.join(path, potential_file) + if full_path.endswith(suffix): full_name = os.path.basename(full_path) break else: # Yes, this is a for-else: http://bit.ly/1ElPkyg continue - + if full_name not in self._plugin_path_cache: self._plugin_path_cache[full_name] = full_path - + self._searched_paths.add(path) for full_name in potential_names: if full_name in self._plugin_path_cache: