summaryrefslogtreecommitdiff
path: root/buildstream/_loader
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-10-26 09:39:20 +0100
committerPhil Dawson <phildawson.0807@gmail.com>2018-10-26 10:20:36 +0000
commit54d89aa1a0b8689284ec7d7f2af011c71da53472 (patch)
treeeed6151164175e7ca098c236a7e1a58880968933 /buildstream/_loader
parentf131c40712225f530dc99a908b6ffd699196bf15 (diff)
downloadbuildstream-54d89aa1a0b8689284ec7d7f2af011c71da53472.tar.gz
_loader/loadelement.py: Use enumerate() in dependency extractiondanielsilverstone-ct/use-enumerate
In cases where elements end up with large numbers of dependencies, the n-squared performance in `_extract_depends_from_node` can produce significant delays during project load. This patch corrects that. In addition we were double-retrieving provenance which was unnecessary. Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
Diffstat (limited to 'buildstream/_loader')
-rw-r--r--buildstream/_loader/loadelement.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/buildstream/_loader/loadelement.py b/buildstream/_loader/loadelement.py
index 72e89879e..1c520f6fa 100644
--- a/buildstream/_loader/loadelement.py
+++ b/buildstream/_loader/loadelement.py
@@ -146,8 +146,8 @@ def _extract_depends_from_node(node, *, key=None):
depends = _yaml.node_get(node, list, key, default_value=[])
output_deps = []
- for dep in depends:
- dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[depends.index(dep)])
+ for index, dep in enumerate(depends):
+ dep_provenance = _yaml.node_get_provenance(node, key=key, indices=[index])
if isinstance(dep, str):
dependency = Dependency(dep, provenance=dep_provenance, dep_type=default_dep_type)
@@ -177,10 +177,8 @@ def _extract_depends_from_node(node, *, key=None):
provenance=dep_provenance)
else:
- index = depends.index(dep)
- p = _yaml.node_get_provenance(node, key=key, indices=[index])
raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dependency is not specified as a string or a dictionary".format(p))
+ "{}: Dependency is not specified as a string or a dictionary".format(dep_provenance))
output_deps.append(dependency)