data tree OPTIMIZE add node into unres list for must only if it really has must
diff --git a/src/resolve.c b/src/resolve.c
index 2403463..a0d1009 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -3597,6 +3597,25 @@
}
int
+resolve_applies_must(const struct lyd_node *node)
+{
+ switch (node->schema->nodetype) {
+ case LYS_CONTAINER:
+ return ((struct lys_node_container *)node->schema)->must_size;
+ case LYS_LEAF:
+ return ((struct lys_node_leaf *)node->schema)->must_size;
+ case LYS_LEAFLIST:
+ return ((struct lys_node_leaflist *)node->schema)->must_size;
+ case LYS_LIST:
+ return ((struct lys_node_list *)node->schema)->must_size;
+ case LYS_ANYXML:
+ return ((struct lys_node_anyxml *)node->schema)->must_size;
+ default:
+ return 0;
+ }
+}
+
+int
resolve_applies_when(const struct lyd_node *node)
{
struct lys_node *parent;
diff --git a/src/resolve.h b/src/resolve.h
index e4b9678..22c9ab1 100644
--- a/src/resolve.h
+++ b/src/resolve.h
@@ -114,6 +114,7 @@
/* get know if resolve_when() is applicable to the node (there is when condition connected with this node) */
int resolve_applies_when(const struct lyd_node *node);
+int resolve_applies_must(const struct lyd_node *node);
struct lys_ident *resolve_identref(struct lys_ident *base, const char *ident_name, struct lyd_node *node);
diff --git a/src/validation.c b/src/validation.c
index bb7625c..8dfd193 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -662,7 +662,7 @@
}
/* check must conditions */
- if (unres_data_add(unres, node, UNRES_MUST) == -1) {
+ if (resolve_applies_must(node) && unres_data_add(unres, node, UNRES_MUST) == -1) {
return EXIT_FAILURE;
}