diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-03 14:41:25 +0100 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-03 15:12:36 +0100 |
commit | 5fbd1b592db0d81d03aaff2599a2d4930306cee8 (patch) | |
tree | 2713e208c8f07adf0d3c7663759ef3e1bdbade35 | |
parent | 49262bda8e5bc3a1886256a848618ae22229135e (diff) | |
download | buildstream-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.pyx | 16 |
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 |