summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-03 14:41:25 +0100
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-03 15:12:36 +0100
commit5fbd1b592db0d81d03aaff2599a2d4930306cee8 (patch)
tree2713e208c8f07adf0d3c7663759ef3e1bdbade35
parent49262bda8e5bc3a1886256a848618ae22229135e (diff)
downloadbuildstream-bschubert/optimize-node_get.tar.gz
_yaml: Optimize node_get to not create dummy Nodes unnecessarily.bschubert/optimize-node_get
This reduces considerably the number of nodes created and thus speeds up the calls to node_get.
-rw-r--r--src/buildstream/_yaml.pyx16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index b33858e86..4505e2f95 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -525,15 +525,15 @@ _sentinel = object()
#
cpdef object node_get(Node node, object expected_type, str key, list indices=None, object default_value=_sentinel, bint allow_none=False):
if indices is None:
- if default_value is _sentinel:
- value = node.value.get(key, Node(default_value, _SYNTHETIC_FILE_INDEX, 0, 0))
- else:
- value = node.value.get(key, Node(default_value, _SYNTHETIC_FILE_INDEX, 0, next_synthetic_counter()))
+ value = node.value.get(key, _sentinel)
- if value.value is _sentinel:
- provenance = node_get_provenance(node)
- raise LoadError(LoadErrorReason.INVALID_DATA,
- "{}: Dictionary did not contain expected key '{}'".format(provenance, key))
+ if value is _sentinel:
+ if default_value is _sentinel:
+ provenance = node_get_provenance(node)
+ raise LoadError(LoadErrorReason.INVALID_DATA,
+ "{}: Dictionary did not contain expected key '{}'".format(provenance, key))
+
+ value = Node(default_value, _SYNTHETIC_FILE_INDEX, 0, next_synthetic_counter())
else:
# Implied type check of the element itself
# No need to synthesise useful node content as we destructure it immediately