From 368e3c83109e52a7dcc314177496800d31ab4832 Mon Sep 17 00:00:00 2001 From: Cristian Ciupitu Date: Thu, 27 Mar 2014 19:56:33 +0200 Subject: [PATCH] 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. --- cloud/gc_storage | 2 +- cloud/s3 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud/gc_storage b/cloud/gc_storage index cbf72aa8e92..4bbf9eabae7 100644 --- a/cloud/gc_storage +++ b/cloud/gc_storage @@ -154,7 +154,7 @@ def keysum(module, gs, bucket, obj): key_check = bucket.get_key(obj) if key_check: 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: module.fail_json(msg="Files uploaded with multipart of gs are not supported with checksum, unable to compute checksum.") return md5_remote diff --git a/cloud/s3 b/cloud/s3 index 6d64a3f43fe..aaa2e0f4ffb 100644 --- a/cloud/s3 +++ b/cloud/s3 @@ -147,7 +147,7 @@ def keysum(module, s3, bucket, obj): key_check = bucket.get_key(obj) if key_check: 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: module.fail_json(msg="Files uploaded with multipart of s3 are not supported with checksum, unable to compute checksum.") return md5_remote