From 02e1fe45e4bb2d7473296d2b8c2114680d9c75c2 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 23 Sep 2009 09:30:46 +0000 Subject: - Speed up ``repoze.bfg.location.lineage`` slightly. --- repoze/bfg/location.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'repoze') diff --git a/repoze/bfg/location.py b/repoze/bfg/location.py index adb01d129..8e8eff671 100644 --- a/repoze/bfg/location.py +++ b/repoze/bfg/location.py @@ -55,5 +55,15 @@ def lineage(model): """ while model is not None: yield model - model = getattr(model, '__parent__', None) + # The common case is that the AttributeError exception below + # is exceptional as long as the developer is a "good citizen" + # who has a root object with a __parent__ of None. Using an + # exception here instead of a getattr with a default is an + # important micro-optimization, because this function is + # called in any non-trivial application over and over again to + # generate URLs and paths. + try: + model = model.__parent__ + except AttributeError: + model = None -- cgit v1.2.3