From 96ff1444f09a95e80a5f6014a802e8afa37a0c82 Mon Sep 17 00:00:00 2001 From: Cristian Ciupitu Date: Thu, 27 Mar 2014 20:30:09 +0200 Subject: [PATCH] Micro-optimization: replace s.find(x)==0 with s.startswith(x) timeit shows a speedup of ~1.4x on Python 2.7.5 x86_64. It also makes the code a bit shorter. --- lib/ansible/inventory/__init__.py | 2 +- library/system/service | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index a8cca8faaf..830d74c01e 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -108,7 +108,7 @@ class Inventory(object): inv_file = open(host_list) first_line = inv_file.readlines()[0] inv_file.close() - if first_line.find('#!') == 0: + if first_line.startswith('#!'): shebang_present = True except: pass diff --git a/library/system/service b/library/system/service index 97a970a951..141b2ac418 100644 --- a/library/system/service +++ b/library/system/service @@ -1008,7 +1008,7 @@ class SunOSService(Service): # enabled true # enabled false for line in stdout.split("\n"): - if line.find("enabled") == 0: + if line.startswith("enabled"): if "true" in line: enabled = True if "temporary" in line: