[Checkins] SVN: bobo/trunk/bobo/src/bobo.py Speed optimization for match and bobo_handle in the _Handler class.
Fabio Tranchitella
kobold at kobold.it
Fri Dec 18 05:25:04 EST 2009
Log message for revision 106746:
Speed optimization for match and bobo_handle in the _Handler class.
The match and bobo_handle properties of the class _Handler were meant to be
executed once, and then cache their return value as an optimization; the code
failed to cache the value (properties are not overridden by
self.__dict__[key]), and thus the routes were computed at every access of the
property.
Now the caching works, storing the bobo_handle and match attributes without
using properties (which has also the advantage that the values are computed at
start-up time instead of computing them at the first execution).
Changed:
U bobo/trunk/bobo/src/bobo.py
-=-
Modified: bobo/trunk/bobo/src/bobo.py
===================================================================
--- bobo/trunk/bobo/src/bobo.py 2009-12-18 10:17:28 UTC (rev 106745)
+++ bobo/trunk/bobo/src/bobo.py 2009-12-18 10:25:03 UTC (rev 106746)
@@ -554,32 +554,29 @@
if order_ is None:
order_ = order()
self.bobo_order = order_
+ self._bobo_handle()
+ self._match()
- @property
- def bobo_handle(self):
+ def _bobo_handle(self):
func = original = self.bobo_original
if self.params:
func = _make_caller(func, self.params)
func = _make_bobo_handle(func, original, self.check, self.content_type)
self.__dict__['bobo_handle'] = func
- return func
- @property
- def match(self):
+ def _match(self):
route_data = _compile_route(self.bobo_route, self.partial)
methods = self.bobo_methods
if methods is None:
- return route_data
-
- def match(request, path, method):
- data = route_data(request, path)
- if data is not None:
- if method not in methods:
- raise MethodNotAllowed(methods)
- return data
-
+ match = route_data
+ else:
+ def match(request, path, method):
+ data = route_data(request, path)
+ if data is not None:
+ if method not in methods:
+ raise MethodNotAllowed(methods)
+ return data
self.__dict__['match'] = match
- return match
def bobo_response(self, *args):
request, path, method = args[-3:]
More information about the checkins
mailing list