mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Micro-optimization: replace s.find(x)!=-1 with x in s
timeit shows a speedup of ~3x on Python 2.7.5 x86_64. It also makes the code a bit shorter.
This commit is contained in:
parent
cda90e3ff6
commit
1eaf85b89f
4 changed files with 5 additions and 5 deletions
|
@ -98,7 +98,7 @@ def not_in_host_file(self, host):
|
||||||
host_fh.close()
|
host_fh.close()
|
||||||
|
|
||||||
for line in data.split("\n"):
|
for line in data.split("\n"):
|
||||||
if line is None or line.find(" ") == -1:
|
if line is None or " " not in line:
|
||||||
continue
|
continue
|
||||||
tokens = line.split()
|
tokens = line.split()
|
||||||
if tokens[0].find(HASHED_KEY_MAGIC) == 0:
|
if tokens[0].find(HASHED_KEY_MAGIC) == 0:
|
||||||
|
|
|
@ -314,7 +314,7 @@ def parse_json(raw_data):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
for t in tokens:
|
for t in tokens:
|
||||||
if t.find("=") == -1:
|
if "=" not in t:
|
||||||
raise errors.AnsibleError("failed to parse: %s" % orig_data)
|
raise errors.AnsibleError("failed to parse: %s" % orig_data)
|
||||||
(key,value) = t.split("=", 1)
|
(key,value) = t.split("=", 1)
|
||||||
if key == 'changed' or 'failed':
|
if key == 'changed' or 'failed':
|
||||||
|
@ -1035,7 +1035,7 @@ def listify_lookup_plugin_terms(terms, basedir, inject):
|
||||||
# not sure why the "/" is in above code :)
|
# not sure why the "/" is in above code :)
|
||||||
try:
|
try:
|
||||||
new_terms = template.template(basedir, "{{ %s }}" % terms, inject)
|
new_terms = template.template(basedir, "{{ %s }}" % terms, inject)
|
||||||
if isinstance(new_terms, basestring) and new_terms.find("{{") != -1:
|
if isinstance(new_terms, basestring) and "{{" in new_terms:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
terms = new_terms
|
terms = new_terms
|
||||||
|
|
|
@ -154,7 +154,7 @@ def keysum(module, gs, bucket, obj):
|
||||||
key_check = bucket.get_key(obj)
|
key_check = bucket.get_key(obj)
|
||||||
if key_check:
|
if key_check:
|
||||||
md5_remote = key_check.etag[1:-1]
|
md5_remote = key_check.etag[1:-1]
|
||||||
etag_multipart = md5_remote.find('-')!=-1 #Check for multipart, etag is not md5
|
etag_multipart = '-' in md5_remote # Check for multipart, etag is not md5
|
||||||
if etag_multipart is True:
|
if etag_multipart is True:
|
||||||
module.fail_json(msg="Files uploaded with multipart of gs are not supported with checksum, unable to compute checksum.")
|
module.fail_json(msg="Files uploaded with multipart of gs are not supported with checksum, unable to compute checksum.")
|
||||||
return md5_remote
|
return md5_remote
|
||||||
|
|
|
@ -147,7 +147,7 @@ def keysum(module, s3, bucket, obj):
|
||||||
key_check = bucket.get_key(obj)
|
key_check = bucket.get_key(obj)
|
||||||
if key_check:
|
if key_check:
|
||||||
md5_remote = key_check.etag[1:-1]
|
md5_remote = key_check.etag[1:-1]
|
||||||
etag_multipart = md5_remote.find('-')!=-1 #Check for multipart, etag is not md5
|
etag_multipart = '-' in md5_remote # Check for multipart, etag is not md5
|
||||||
if etag_multipart is True:
|
if etag_multipart is True:
|
||||||
module.fail_json(msg="Files uploaded with multipart of s3 are not supported with checksum, unable to compute checksum.")
|
module.fail_json(msg="Files uploaded with multipart of s3 are not supported with checksum, unable to compute checksum.")
|
||||||
return md5_remote
|
return md5_remote
|
||||||
|
|
Loading…
Reference in a new issue