summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2017-10-13 16:49:51 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2017-10-13 19:46:57 -0700
commitf58c5030912d612140ef7177825f9d78babe62bf (patch)
tree4e238e0bde027c273d85727936b1ceea929d3039 /lib
parent9ccaf6474d1561dbcb6fbf5c6001726c7a01e98f (diff)
downloadspack-f58c5030912d612140ef7177825f9d78babe62bf.tar.gz
spack-f58c5030912d612140ef7177825f9d78babe62bf.tar.bz2
spack-f58c5030912d612140ef7177825f9d78babe62bf.tar.xz
spack-f58c5030912d612140ef7177825f9d78babe62bf.zip
avoid creating lots of dictionaries in traverse_edges()
- This is an optimization to the way traverse_edges iterates over successors. - Previous version called dependencies_dict(), which involved a lot of redundant work (creating dicts and calling caonical_deptype)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/spec.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 7704d7df72..ed204deb9e 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -1337,27 +1337,26 @@ class Spec(object):
# Edge traversal yields but skips children of visited nodes
if not (key in visited and cover == 'edges'):
+ visited.add(key)
+
# This code determines direction and yields the children/parents
if direction == 'children':
- successors = self.dependencies_dict(deptype)
- succ = lambda s: s.spec
+ where = self._dependencies
+ succ = lambda dspec: dspec.spec
elif direction == 'parents':
- successors = self.dependents_dict(deptype)
- succ = lambda s: s.parent
+ where = self._dependents
+ succ = lambda dspec: dspec.parent
else:
raise ValueError('Invalid traversal direction: %s' % direction)
- visited.add(key)
- for name, dspec in sorted(successors.items()):
- child = successors[name]
- children = succ(child).traverse_edges(
- visited,
- d=(d + 1),
- deptype=deptype,
- dep_spec=dspec,
- **kwargs)
- for elt in children:
- yield elt
+ for name, dspec in sorted(where.items()):
+ dt = dspec.deptypes
+ if dt and not any(d in deptype for d in dt):
+ continue
+
+ for child in succ(dspec).traverse_edges(
+ visited, d + 1, deptype, dspec, **kwargs):
+ yield child
# Postorder traversal yields after successors
if yield_me and order == 'post':