Skip to content
Snippets Groups Projects
Commit bf825da5 authored by Daniel Silverstone's avatar Daniel Silverstone
Browse files

_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: default avatarDaniel Silverstone <daniel.silverstone@codethink.co.uk>
parent bb965ba2
No related branches found
No related tags found
No related merge requests found
......@@ -1177,6 +1177,10 @@ def list_copy(source):
return copy
# Helpers for the assertions
__node_assert_composition_directives = ('(>)', '(<)', '(=)')
# node_final_assertions()
#
# This must be called on a fully loaded and composited node,
......@@ -1195,22 +1199,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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment