summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt9
-rw-r--r--repoze/bfg/location.py12
2 files changed, 20 insertions, 1 deletions
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