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. --- CHANGES.txt | 9 +++++++++ repoze/bfg/location.py | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index bd28f160b..42a87940c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,12 @@ +Next release +============ + +Features +-------- + +- Speed up ``repoze.bfg.location.lineage`` slightly. + + 1.1a4 (2009-09-23) ================== 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