summaryrefslogtreecommitdiff
path: root/repoze/bfg/traversal.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-06-22 02:30:13 +0000
committerChris McDonough <chrism@agendaless.com>2009-06-22 02:30:13 +0000
commit1cd5984995fefa64bdb7bdd47e6e09e8d424f6d2 (patch)
tree5d111a0d62170b38320a9910c25306610a4987e2 /repoze/bfg/traversal.py
parentffdbee31ce747c723988ef5ae94a0d02400718ba (diff)
downloadpyramid-1cd5984995fefa64bdb7bdd47e6e09e8d424f6d2.tar.gz
pyramid-1cd5984995fefa64bdb7bdd47e6e09e8d424f6d2.tar.bz2
pyramid-1cd5984995fefa64bdb7bdd47e6e09e8d424f6d2.zip
- The values of ``subpath``, ``traversed``, and ``virtual_root_path``
attached to the request object are always now tuples instead of lists (performance).
Diffstat (limited to 'repoze/bfg/traversal.py')
-rw-r--r--repoze/bfg/traversal.py46
1 files changed, 27 insertions, 19 deletions
diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py
index 16ab7c9f4..428553ec6 100644
--- a/repoze/bfg/traversal.py
+++ b/repoze/bfg/traversal.py
@@ -505,52 +505,60 @@ class ModelGraphTraverser(object):
path = environ['PATH_INFO']
except KeyError:
path = '/'
+
try:
vroot_path_string = environ[VH_ROOT_KEY]
except KeyError:
- vroot_path = []
+ vroot_path = ()
vroot_idx = 0
else:
- vroot_path = list(traversal_path(vroot_path_string))
+ vroot_path = traversal_path(vroot_path_string)
vroot_idx = len(vroot_path)
path = vroot_path_string + path
path = traversal_path(path)
-
- traversed = []
-
ob = vroot = self.root
- name = ''
+
+ # 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=traversed, virtual_root=vroot,
- virtual_root_path=vroot_path, root=self.root)
+ 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=traversed, virtual_root=vroot,
- virtual_root_path=vroot_path, root=self.root)
+ 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=traversed, virtual_root=vroot,
- virtual_root_path=vroot_path, root=self.root)
+ 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
- traversed.append(segment)
ob = next
i += 1
+ j += 1
return dict(context=ob, view_name=u'', subpath=subpath,
- traversed=traversed, virtual_root=vroot,
- virtual_root_path=vroot_path,
- root=self.root)
+ traversed=path, virtual_root=vroot,
+ virtual_root_path=vroot_path, root=self.root)
class TraversalContextURL(object):
""" The IContextURL adapter used to generate URLs for a context