mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07: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
a7da5d8702
commit
0749112286
19 changed files with 50 additions and 48 deletions
|
@ -95,7 +95,7 @@ class ModuleReplacer(object):
|
|||
|
||||
for line in lines:
|
||||
|
||||
if line.find(REPLACER) != -1:
|
||||
if REPLACER in line:
|
||||
output.write(self.slurp(os.path.join(self.snippet_path, "basic.py")))
|
||||
snippet_names.append('basic')
|
||||
elif line.startswith('from ansible.module_utils.'):
|
||||
|
@ -103,7 +103,7 @@ class ModuleReplacer(object):
|
|||
import_error = False
|
||||
if len(tokens) != 3:
|
||||
import_error = True
|
||||
if line.find(" import *") == -1:
|
||||
if " import *" not in line:
|
||||
import_error = True
|
||||
if import_error:
|
||||
raise errors.AnsibleError("error importing module in %s, expecting format like 'from ansible.module_utils.basic import *'" % module_path)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue