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.
reviewable/pr18780/r1
Cristian Ciupitu 11 years ago
parent c757b6624f
commit 368e3c8310

@ -154,7 +154,7 @@ def keysum(module, gs, bucket, obj):
key_check = bucket.get_key(obj) key_check = bucket.get_key(obj)
if key_check: if key_check:
md5_remote = key_check.etag[1:-1] 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: if etag_multipart is True:
module.fail_json(msg="Files uploaded with multipart of gs are not supported with checksum, unable to compute checksum.") module.fail_json(msg="Files uploaded with multipart of gs are not supported with checksum, unable to compute checksum.")
return md5_remote return md5_remote

@ -147,7 +147,7 @@ def keysum(module, s3, bucket, obj):
key_check = bucket.get_key(obj) key_check = bucket.get_key(obj)
if key_check: if key_check:
md5_remote = key_check.etag[1:-1] 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: if etag_multipart is True:
module.fail_json(msg="Files uploaded with multipart of s3 are not supported with checksum, unable to compute checksum.") module.fail_json(msg="Files uploaded with multipart of s3 are not supported with checksum, unable to compute checksum.")
return md5_remote return md5_remote

Loading…
Cancel
Save