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
This commit is contained in:
Venkateswarlu Pallamala 2015-11-04 00:53:05 -08:00
parent 7242c4a006
commit 48421f902e

View File

@ -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):
'''