diff options
author | Cristian Ciupitu <cristian.ciupitu@yahoo.com> | 2014-01-23 17:02:17 +0200 |
---|---|---|
committer | Michael DeHaan <michael.dehaan@gmail.com> | 2014-03-16 13:10:28 -0400 |
commit | 7f681c33a2a4b6f7d074468a039476c95974de04 (patch) | |
tree | 5baf33f5e60f7e55d97376d6ec75d1c6d15c7cfc | |
parent | c3e8a51374545c895fb18fd40fa3fd1c9be187ee (diff) | |
download | ansible-modules-extras-7f681c33a2a4b6f7d074468a039476c95974de04.tar.gz |
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.
-rw-r--r-- | cloud/virt | 2 | ||||
-rw-r--r-- | commands/command | 2 | ||||
-rw-r--r-- | database/mysql_user | 2 | ||||
-rw-r--r-- | files/file | 2 | ||||
-rw-r--r-- | system/open_iscsi | 2 | ||||
-rw-r--r-- | system/service | 18 |
6 files changed, 14 insertions, 14 deletions
@@ -120,7 +120,7 @@ class LibvirtConnection(object): cmd = "uname -r" rc, stdout, stderr = self.module.run_command(cmd) - if stdout.find("xen") != -1: + if "xen" in stdout: conn = libvirt.open(None) else: conn = libvirt.open(uri) diff --git a/commands/command b/commands/command index ba9ae30a..b35501f1 100644 --- a/commands/command +++ b/commands/command @@ -180,7 +180,7 @@ class CommandModule(AnsibleModule): params['removes'] = None params['shell'] = False params['executable'] = None - if args.find("#USE_SHELL") != -1: + if "#USE_SHELL" in args: args = args.replace("#USE_SHELL", "") params['shell'] = True diff --git a/database/mysql_user b/database/mysql_user index e7fad3d7..b7c84fd1 100644 --- a/database/mysql_user +++ b/database/mysql_user @@ -259,7 +259,7 @@ def privileges_unpack(priv): output = {} for item in priv.split('/'): pieces = item.split(':') - if pieces[0].find('.') != -1: + if '.' in pieces[0]: pieces[0] = pieces[0].split('.') for idx, piece in enumerate(pieces): if pieces[0][idx] != "*": @@ -168,7 +168,7 @@ def main(): f = open(path) b = f.read(8192) f.close() - if b.find("\x00") != -1: + if "\x00" in b: appears_binary = True except: pass diff --git a/system/open_iscsi b/system/open_iscsi index 2e57727c..3fd2b1a5 100644 --- a/system/open_iscsi +++ b/system/open_iscsi @@ -138,7 +138,7 @@ def iscsi_get_cached_nodes(module, portal=None): # older versions of scsiadm don't have nice return codes # for newer versions see iscsiadm(8); also usr/iscsiadm.c for details # err can contain [N|n]o records... - elif rc == 21 or (rc == 255 and err.find("o records found") != -1): + elif rc == 21 or (rc == 255 and "o records found" in err): nodes = [] else: module.fail_json(cmd=cmd, rc=rc, msg=err) diff --git a/system/service b/system/service index 5180a14d..ed30b72a 100644 --- a/system/service +++ b/system/service @@ -483,9 +483,9 @@ class LinuxService(Service): if self.svc_initctl and self.running is None: # check the job status by upstart response initctl_rc, initctl_status_stdout, initctl_status_stderr = self.execute_command("%s status %s" % (self.svc_initctl, self.name)) - if initctl_status_stdout.find("stop/waiting") != -1: + if "stop/waiting" in initctl_status_stdout: self.running = False - elif initctl_status_stdout.find("start/running") != -1: + elif "start/running" in initctl_status_stdout: self.running = True if self.svc_cmd and self.svc_cmd.endswith("rc-service") and self.running is None: @@ -525,7 +525,7 @@ class LinuxService(Service): # if the job status is still not known check it by special conditions if self.running is None: - if self.name == 'iptables' and status_stdout.find("ACCEPT") != -1: + if self.name == 'iptables' and "ACCEPT" in status_stdout: # iptables status command output is lame # TODO: lookup if we can use a return code for this instead? self.running = True @@ -631,16 +631,16 @@ class LinuxService(Service): if line.startswith('rename'): self.changed = True break - elif self.enable and line.find('do not exist') != -1: + elif self.enable and 'do not exist' in line: self.changed = True break - elif not self.enable and line.find('already exist') != -1: + elif not self.enable and 'already exist' in line: self.changed = True break # Debian compatibility for line in err.splitlines(): - if self.enable and line.find('no runlevel symlinks to modify') != -1: + if self.enable and 'no runlevel symlinks to modify' in line: self.changed = True break @@ -982,9 +982,9 @@ class SunOSService(Service): # enabled false for line in stdout.split("\n"): if line.find("enabled") == 0: - if line.find("true") != -1: + if "true" in line: enabled = True - if line.find("temporary") != -1: + if "temporary" in line: temporary = True startup_enabled = (enabled and not temporary) or (not enabled and temporary) @@ -1176,7 +1176,7 @@ def main(): (rc, out, err) = service.modify_service_state() if rc != 0: - if err and err.find("is already") != -1: + if err and "is already" in err: # upstart got confused, one such possibility is MySQL on Ubuntu 12.04 # where status may report it has no start/stop links and we could # not get accurate status |