diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2019-02-12 14:22:13 +0000 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2019-02-12 15:12:30 +0000 |
commit | 69ee11c61b98d3bee3c2449c58a4673830027865 (patch) | |
tree | bb012377defde6e0c5c56cda10f39edb524a8dda /buildstream/_yaml.py | |
parent | b6f08e1b8aa9e7ea8f97a2828f16aa002bd9c904 (diff) | |
download | buildstream-69ee11c61b98d3bee3c2449c58a4673830027865.tar.gz |
_yaml.py: Reduce cost of node_final_assertions
By re-using the isinstance replacements from earlier commits and
using a tuple of the string constants for checking for composition
markers, we reduce the cost of node_final_assertions by two thirds
in basic testing.
Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
Diffstat (limited to 'buildstream/_yaml.py')
-rw-r--r-- | buildstream/_yaml.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py index 0c2fcfabb..7e12183e3 100644 --- a/buildstream/_yaml.py +++ b/buildstream/_yaml.py @@ -1109,6 +1109,10 @@ __LIST_TYPES = (list, yaml.comments.CommentedSeq) # copying tactic. __PROVENANCE_TYPES = (Provenance, DictProvenance, MemberProvenance, ElementProvenance) +# These are the directives used to compose lists, we need this because it's +# slightly faster during the node_final_assertions checks +__NODE_ASSERT_COMPOSITION_DIRECTIVES = ('(>)', '(<)', '(=)') + def node_chain_copy(source): copy = ChainMap({}, source) @@ -1202,22 +1206,26 @@ def node_final_assertions(node): # indicates that the user intended to override a list which # never existed in the underlying data # - if key in ['(>)', '(<)', '(=)']: + if key in __NODE_ASSERT_COMPOSITION_DIRECTIVES: provenance = node_get_provenance(node, key) raise LoadError(LoadErrorReason.TRAILING_LIST_DIRECTIVE, "{}: Attempt to override non-existing list".format(provenance)) - if isinstance(value, collections.abc.Mapping): + value_type = type(value) + + if value_type in __DICT_TYPES: node_final_assertions(value) - elif isinstance(value, list): + elif value_type in __LIST_TYPES: list_final_assertions(value) def list_final_assertions(values): for value in values: - if isinstance(value, collections.abc.Mapping): + value_type = type(value) + + if value_type in __DICT_TYPES: node_final_assertions(value) - elif isinstance(value, list): + elif value_type in __LIST_TYPES: list_final_assertions(value) |