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:
Cristian Ciupitu 2014-03-27 19:56:33 +02:00
commit 1eaf85b89f
4 changed files with 5 additions and 5 deletions

View file

@ -314,7 +314,7 @@ def parse_json(raw_data):
raise
for t in tokens:
if t.find("=") == -1:
if "=" not in t:
raise errors.AnsibleError("failed to parse: %s" % orig_data)
(key,value) = t.split("=", 1)
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 :)
try:
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
else:
terms = new_terms