mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-14 21:01:13 +00:00
Performance improvement using in-operator on dicts
Just a small cleanup for the existing occurrences. Using the in-operator for hash lookups is faster than using .keys() http://stackoverflow.com/questions/29314269/why-do-key-in-dict-and-key-in-dict-keys-have-the-same-output
This commit is contained in:
@@ -2724,7 +2724,7 @@ class GenericBsdIfconfigNetwork(Network):
|
||||
return []
|
||||
|
||||
def merge_default_interface(self, defaults, interfaces, ip_type):
|
||||
if not 'interface' in defaults.keys():
|
||||
if 'interface' not in defaults:
|
||||
return
|
||||
if not defaults['interface'] in interfaces:
|
||||
return
|
||||
@@ -3045,7 +3045,7 @@ class SunOSNetwork(GenericBsdIfconfigNetwork):
|
||||
|
||||
def parse_interface_line(self, words, current_if, interfaces):
|
||||
device = words[0][0:-1]
|
||||
if device not in interfaces.keys():
|
||||
if device not in interfaces:
|
||||
current_if = {'device': device, 'ipv4': [], 'ipv6': [], 'type': 'unknown'}
|
||||
else:
|
||||
current_if = interfaces[device]
|
||||
|
||||
@@ -268,12 +268,12 @@ class Task(Base, Conditional, Taggable, Become):
|
||||
else:
|
||||
env = []
|
||||
for env_item in value:
|
||||
if isinstance(env_item, (string_types, AnsibleUnicode)) and env_item in templar._available_variables.keys():
|
||||
if isinstance(env_item, (string_types, AnsibleUnicode)) and env_item in templar._available_variables:
|
||||
env[env_item] = templar.template(env_item, convert_bare=False)
|
||||
elif isinstance(value, dict):
|
||||
env = dict()
|
||||
for env_item in value:
|
||||
if isinstance(env_item, (string_types, AnsibleUnicode)) and env_item in templar._available_variables.keys():
|
||||
if isinstance(env_item, (string_types, AnsibleUnicode)) and env_item in templar._available_variables:
|
||||
env[env_item] = templar.template(value[env_item], convert_bare=False)
|
||||
|
||||
# at this point it should be a simple string
|
||||
|
||||
@@ -92,13 +92,13 @@ class CallbackModule(CallbackBase):
|
||||
subject = 'Failed: %s' % attach
|
||||
body = 'The following task failed for host ' + host + ':\n\n%s\n\n' % attach
|
||||
|
||||
if 'stdout' in res._result.keys() and res._result['stdout']:
|
||||
if 'stdout' in res._result and res._result['stdout']:
|
||||
subject = res._result['stdout'].strip('\r\n').split('\n')[-1]
|
||||
body += 'with the following output in standard output:\n\n' + res._result['stdout'] + '\n\n'
|
||||
if 'stderr' in res._result.keys() and res._result['stderr']:
|
||||
if 'stderr' in res._result and res._result['stderr']:
|
||||
subject = res._result['stderr'].strip('\r\n').split('\n')[-1]
|
||||
body += 'with the following output in standard error:\n\n' + res._result['stderr'] + '\n\n'
|
||||
if 'msg' in res._result.keys() and res._result['msg']:
|
||||
if 'msg' in res._result and res._result['msg']:
|
||||
subject = res._result['msg'].strip('\r\n').split('\n')[0]
|
||||
body += 'with the following message:\n\n' + res._result['msg'] + '\n\n'
|
||||
body += 'A complete dump of the error:\n\n' + self._dump_results(res._result)
|
||||
|
||||
@@ -104,7 +104,7 @@ def get_docstring(filename, verbose=False):
|
||||
doc['notes'] = []
|
||||
doc['notes'].extend(notes)
|
||||
|
||||
if 'options' not in fragment.keys():
|
||||
if 'options' not in fragment:
|
||||
raise Exception("missing options in fragment, possibly misformatted?")
|
||||
|
||||
for key, value in fragment.items():
|
||||
|
||||
Reference in New Issue
Block a user