From 74f2b4105b32fe719c4ce7ba3ad86f1abe54ed3b Mon Sep 17 00:00:00 2001 From: Sylvain Th?nault Date: Thu, 11 Apr 2013 11:25:08 +0200 Subject: [registry] change select_or_none implementation to remove one level of indirection Rational: when analyzing cubicweb selectors performance, it has been found that the cost of emiting NoSelectableObject and catching it was higher than returning None and testing for None values. Also, it will be definitly an improvment here as we avoid calling an intermediary function that test for None and raise the exception if needed. --- registry.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'registry.py') diff --git a/registry.py b/registry.py index 4afdfb9..0dc7a21 100644 --- a/registry.py +++ b/registry.py @@ -1,4 +1,4 @@ -# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. +# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This file is part of Logilab-common. @@ -360,8 +360,8 @@ class Registry(dict): according to the given context, or None if no object applies. """ try: - return self.select(__oid, *args, **kwargs) - except (NoSelectableObject, ObjectNotFound): + return self._select_best(self[__oid], *args, **kwargs) + except ObjectNotFound: return None def possible_objects(self, *args, **kwargs): -- cgit v1.2.1