summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-09-23 09:30:46 +0000
committerChris McDonough <chrism@agendaless.com>2009-09-23 09:30:46 +0000
commit02e1fe45e4bb2d7473296d2b8c2114680d9c75c2 (patch)
treed17e2b6aa60a2fd278d532a84e3b0c57f24d215c
parente835cc22e93fb722d75b567f9092cd8133297539 (diff)
downloadpyramid-02e1fe45e4bb2d7473296d2b8c2114680d9c75c2.tar.gz
pyramid-02e1fe45e4bb2d7473296d2b8c2114680d9c75c2.tar.bz2
pyramid-02e1fe45e4bb2d7473296d2b8c2114680d9c75c2.zip
- Speed up ``repoze.bfg.location.lineage`` slightly.
-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