summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2016-09-29 01:46:16 -0600
committerBert JW Regeer <bertjw@regeer.org>2016-09-29 02:15:19 -0600
commitd902761d6b77a061d98939901729f3a3028b7a5e (patch)
tree7863ba782b60219ed9b3d6326d8d019fd8f78fee
parent310477ff453011194275c7e897a48cacab95d0c6 (diff)
downloadwebob-bugfix/exc_performance.tar.gz
Move the _lazified class out of the lazify functionbugfix/exc_performance
Capturing the function, and returning a new object from a class that is defined within the capturing function seems to cause some sort of really pathological behavior that causes lazify() to take up a bunch of CPU time, especially when it is part of a hot code path. Thanks to Martijn Faassen for reporting! Closes #282
-rw-r--r--webob/exc.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/webob/exc.py b/webob/exc.py
index b615cd4..deffc64 100644
--- a/webob/exc.py
+++ b/webob/exc.py
@@ -185,13 +185,18 @@ tag_re = re.compile(r'<.*?>', re.S)
br_re = re.compile(r'<br.*?>', re.I | re.S)
comment_re = re.compile(r'<!--|-->')
+class _lazified(object):
+ def __init__(self, func, value):
+ self.func = func
+ self.value = value
+
+ def __str__(self):
+ return self.func(self.value)
+
def lazify(func):
- class _lazyfied(object):
- def __init__(self, s):
- self._s = s
- def __str__(self):
- return func(self._s)
- return _lazyfied
+ def wrapper(value):
+ return _lazified(func, value)
+ return wrapper
def no_escape(value):
if value is None: