summaryrefslogtreecommitdiff
path: root/repoze/bfg/traversal.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-06-22 02:49:41 +0000
committerChris McDonough <chrism@agendaless.com>2009-06-22 02:49:41 +0000
commitd70fd93e4b76369edea80ac1ded9da9ac0a93289 (patch)
tree988fb7bc31ea1a19616f9ef82aab3e478170dc09 /repoze/bfg/traversal.py
parent1cd5984995fefa64bdb7bdd47e6e09e8d424f6d2 (diff)
downloadpyramid-d70fd93e4b76369edea80ac1ded9da9ac0a93289.tar.gz
pyramid-d70fd93e4b76369edea80ac1ded9da9ac0a93289.tar.bz2
pyramid-d70fd93e4b76369edea80ac1ded9da9ac0a93289.zip
More micro-optimizations to the default traverser.
Fix registerModels to use the right traversal info names.
Diffstat (limited to 'repoze/bfg/traversal.py')
-rw-r--r--repoze/bfg/traversal.py80
1 files changed, 43 insertions, 37 deletions
diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py
index 428553ec6..59ad9115d 100644
--- a/repoze/bfg/traversal.py
+++ b/repoze/bfg/traversal.py
@@ -516,45 +516,51 @@ class ModelGraphTraverser(object):
vroot_idx = len(vroot_path)
path = vroot_path_string + path
- path = traversal_path(path)
ob = vroot = self.root
- # in case you're wondering, we do dead reckoning here instead
- # of pushing and popping temporary lists for speed purposes
-
- i = 1
- j = vroot_idx
-
- for segment in path:
- if segment[:2] =='@@':
- return dict(context=ob, view_name=segment[2:],
- subpath=path[i:], traversed=path[:j],
- virtual_root=vroot,
- virtual_root_path=vroot_path,
- root=self.root)
- try:
- getitem = ob.__getitem__
- except AttributeError:
- return dict(context=ob, view_name=segment,
- subpath=path[i:], traversed=path[:j],
- virtual_root=vroot,
- virtual_root_path=vroot_path,
- root=self.root)
-
- try:
- next = getitem(segment)
- except KeyError:
- return dict(context=ob, view_name=segment,
- subpath=path[i:], traversed=path[:j],
- virtual_root=vroot,
- virtual_root_path=vroot_path,
- root=self.root)
-
- if vroot_idx == i-1:
- vroot = ob
- ob = next
- i += 1
- j += 1
+ if (not path) or path == '/':
+ # save a call to traversal_path if we know it's going to return
+ # the empty tuple
+ path = ()
+ else:
+ path = traversal_path(path)
+
+ # in case you're wondering, we do dead reckoning here instead
+ # of pushing and popping temporary lists for speed purposes
+
+ i = 1
+ j = vroot_idx
+
+ for segment in path:
+ if segment[:2] =='@@':
+ return dict(context=ob, view_name=segment[2:],
+ subpath=path[i:], traversed=path[:j],
+ virtual_root=vroot,
+ virtual_root_path=vroot_path,
+ root=self.root)
+ try:
+ getitem = ob.__getitem__
+ except AttributeError:
+ return dict(context=ob, view_name=segment,
+ subpath=path[i:], traversed=path[:j],
+ virtual_root=vroot,
+ virtual_root_path=vroot_path,
+ root=self.root)
+
+ try:
+ next = getitem(segment)
+ except KeyError:
+ return dict(context=ob, view_name=segment,
+ subpath=path[i:], traversed=path[:j],
+ virtual_root=vroot,
+ virtual_root_path=vroot_path,
+ root=self.root)
+
+ if vroot_idx == i-1:
+ vroot = ob
+ ob = next
+ i += 1
+ j += 1
return dict(context=ob, view_name=u'', subpath=subpath,
traversed=path, virtual_root=vroot,