Skip to content

Commit f40b998

Browse files
committed
feat: check dict length with node length for quick unique key check
1 parent fbcffa6 commit f40b998

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/annotatedyaml/loader.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,16 @@ def _handle_mapping_tag(
406406
loader.flatten_mapping(node)
407407
nodes = loader.construct_pairs(node)
408408

409+
# Check first if length of dict is equal to the length of the nodes
410+
# This is a quick way to check if the keys are unique
411+
try:
412+
conv_dict = dict(nodes)
413+
except TypeError:
414+
pass
415+
else:
416+
if len(conv_dict) == len(nodes):
417+
return _add_reference_to_node_class(NodeDictClass(conv_dict), loader, node)
418+
409419
seen: dict = {}
410420
for (key, _), (child_node, _) in zip(nodes, node.value, strict=False):
411421
line = child_node.start_mark.line

0 commit comments

Comments
 (0)