From 48421f902e2e293a3c9ef672dbec5971ca530fd6 Mon Sep 17 00:00:00 2001 From: Venkateswarlu Pallamala Date: Wed, 4 Nov 2015 00:53:05 -0800 Subject: [PATCH] Optimize the code performance Usually, the number of characters in FORBIDDEN_CHARS are fewer than the number of characters in the req.path - so it's better to use smaller count for the outer loop. Change-Id: I78b7e0ff4cae1cc90e8d29d7bddcec7fe0ba4bd4 --- swift/common/middleware/name_check.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/swift/common/middleware/name_check.py b/swift/common/middleware/name_check.py index c2ddbbaf0f..c6fb974011 100644 --- a/swift/common/middleware/name_check.py +++ b/swift/common/middleware/name_check.py @@ -79,12 +79,7 @@ class NameCheckMiddleware(object): self.logger.debug("name_check: self.forbidden_chars %s" % self.forbidden_chars) - for c in unquote(req.path): - if c in self.forbidden_chars: - return True - else: - pass - return False + return any((c in unquote(req.path)) for c in self.forbidden_chars) def check_length(self, req): ''' @@ -93,10 +88,7 @@ class NameCheckMiddleware(object): Returns False if the length is <= the maximum ''' length = len(unquote(req.path)) - if length > self.maximum_length: - return True - else: - return False + return length > self.maximum_length def check_regexp(self, req): '''