summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2019-04-01 11:40:38 +0100
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2019-04-01 15:30:18 +0100
commitac17fe723644eaecbd1f5b35383ede277cdbd0df (patch)
treefd61cb7b4c8942d4c79dac107588feb7c646c6f6
parent906612a0e340329f3317b0f152735c8dc8910efe (diff)
downloadbuildstream-ac17fe723644eaecbd1f5b35383ede277cdbd0df.tar.gz
_yaml.py::node_get(): Only construct path on errorkinnison/cleanups
We don't need to spend the CPU constructing path except when there is an error which needs it, so don't. Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-rw-r--r--buildstream/_yaml.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index 519d91b34..5184485de 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -452,7 +452,6 @@ _sentinel = object()
def node_get(node, expected_type, key, indices=None, *, default_value=_sentinel, allow_none=False):
assert type(node) is Node
- path = key
if indices is None:
if default_value is _sentinel:
value = node[0].get(key, Node(default_value, None, 0, 0))
@@ -471,7 +470,6 @@ def node_get(node, expected_type, key, indices=None, *, default_value=_sentinel,
value = value[0][index]
if type(value) is not Node:
value = (value,)
- path += '[{:d}]'.format(index)
# Optionally allow None as a valid value for any type
if value[0] is None and (allow_none or default_value is None):
@@ -499,6 +497,12 @@ def node_get(node, expected_type, key, indices=None, *, default_value=_sentinel,
raise ValueError()
except (ValueError, TypeError):
provenance = node_get_provenance(node, key=key, indices=indices)
+ if indices:
+ path = [key]
+ path.extend("[{:d}]".format(i) for i in indices)
+ path = "".join(path)
+ else:
+ path = key
raise LoadError(LoadErrorReason.INVALID_DATA,
"{}: Value of '{}' is not of the expected type '{}'"
.format(provenance, path, expected_type.__name__))