@@ -1505,14 +1505,7 @@ lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly
15051505 return LY_SUCCESS ;
15061506}
15071507
1508- /**
1509- * @brief Check the equality of the two schemas from different contexts.
1510- *
1511- * @param schema1 of first node.
1512- * @param schema2 of second node.
1513- * @return 1 if the schemas are equal otherwise 0.
1514- */
1515- static ly_bool
1508+ ly_bool
15161509lyd_compare_schema_equal (const struct lysc_node * schema1 , const struct lysc_node * schema2 )
15171510{
15181511 if (!schema1 && !schema2 ) {
@@ -1521,7 +1514,9 @@ lyd_compare_schema_equal(const struct lysc_node *schema1, const struct lysc_node
15211514 return 0 ;
15221515 }
15231516
1524- assert (schema1 -> module -> ctx != schema2 -> module -> ctx );
1517+ if (schema1 -> module -> ctx == schema2 -> module -> ctx ) {
1518+ return (schema1 == schema2 ) ? 1 : 0 ;
1519+ }
15251520
15261521 if (schema1 -> nodetype != schema2 -> nodetype ) {
15271522 return 0 ;
@@ -3177,10 +3172,11 @@ lyd_find_meta(const struct lyd_meta *first, const struct lys_module *module, con
31773172LIBYANG_API_DEF LY_ERR
31783173lyd_find_sibling_first (const struct lyd_node * siblings , const struct lyd_node * target , struct lyd_node * * match )
31793174{
3180- struct lyd_node * * match_p , * iter , * dup = NULL , * parent ;
3175+ struct lyd_node * * match_p , * iter , * parent ;
31813176 ly_bool found ;
31823177
31833178 LY_CHECK_ARG_RET (NULL , target , LY_EINVAL );
3179+
31843180 if (!siblings ) {
31853181 /* no data */
31863182 if (match ) {
@@ -3189,15 +3185,9 @@ lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *t
31893185 return LY_ENOTFOUND ;
31903186 }
31913187
3192- if (LYD_CTX (siblings ) != LYD_CTX (target )) {
3193- /* create a duplicate in this context */
3194- LY_CHECK_RET (lyd_dup_single_to_ctx (target , lyd_dup_get_top_ctx (siblings ), NULL , 0 , & dup ));
3195- target = dup ;
3196- }
3197-
3198- if ((siblings -> schema && target -> schema && (lysc_data_parent (siblings -> schema ) != lysc_data_parent (target -> schema )))) {
3188+ if ((siblings -> schema && target -> schema &&
3189+ !lyd_compare_schema_equal (lysc_data_parent (siblings -> schema ), lysc_data_parent (target -> schema )))) {
31993190 /* schema mismatch */
3200- lyd_free_tree (dup );
32013191 if (match ) {
32023192 * match = NULL ;
32033193 }
@@ -3214,7 +3204,9 @@ lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *t
32143204 if (lysc_is_dup_inst_list (target -> schema )) {
32153205 /* we must search the instances from beginning to find the first matching one */
32163206 found = 0 ;
3217- LYD_LIST_FOR_INST (siblings , target -> schema , iter ) {
3207+ for (lyd_find_sibling_val (siblings , target -> schema , NULL , 0 , & iter );
3208+ iter && lyd_compare_schema_equal (iter -> schema , target -> schema );
3209+ iter = iter -> next ) {
32183210 if (!lyd_compare_single (target , iter , LYD_COMPARE_FULL_RECURSION )) {
32193211 found = 1 ;
32203212 break ;
@@ -3249,7 +3241,6 @@ lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *t
32493241 }
32503242 }
32513243
3252- lyd_free_tree (dup );
32533244 if (!siblings ) {
32543245 if (match ) {
32553246 * match = NULL ;
0 commit comments