diff options
author | Benjamin Schubert <contact@benschubert.me> | 2019-06-05 21:16:50 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-06-06 15:53:43 +0000 |
commit | 8f6e36acea77b35f454a53383a94b8fb838957fd (patch) | |
tree | 65a424a26f1e02d2776b2ff3e983cddc4ab34690 /src/buildstream/_yaml.pyx | |
parent | baec142e623f9e8a4efd93183ac2f7ef15d84b06 (diff) | |
download | buildstream-8f6e36acea77b35f454a53383a94b8fb838957fd.tar.gz |
_loader/types: cimport yaml functions for better speed
- _yaml: export node_validate function as Cython, as it was not done
before. This requires rewriting the function to remove a closure.
- Optimize node check by not calling is_node().
Diffstat (limited to 'src/buildstream/_yaml.pyx')
-rw-r--r-- | src/buildstream/_yaml.pyx | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx index 4505e2f95..f14b55e51 100644 --- a/src/buildstream/_yaml.pyx +++ b/src/buildstream/_yaml.pyx @@ -1119,16 +1119,17 @@ cpdef object node_sanitize(object node, object dict_type=OrderedDict): # LoadError: In the case that the specified node contained # one or more invalid keys # -def node_validate(Node node, list valid_keys): +cpdef void node_validate(Node node, list valid_keys) except *: # Probably the fastest way to do this: https://stackoverflow.com/a/23062482 cdef set valid_keys_set = set(valid_keys) - invalid = next((key for key in node.value if key not in valid_keys_set), None) + cdef str key - if invalid: - provenance = node_get_provenance(node, key=invalid) - raise LoadError(LoadErrorReason.INVALID_DATA, - "{}: Unexpected key: {}".format(provenance, invalid)) + for key in node.value: + if key not in valid_keys_set: + provenance = node_get_provenance(node, key=key) + raise LoadError(LoadErrorReason.INVALID_DATA, + "{}: Unexpected key: {}".format(provenance, key)) # Node copying |