@@ -844,6 +844,7 @@ set_init(struct lyxp_set *new, const struct lyxp_set *set)
844844{
845845 memset (new , 0 , sizeof * new );
846846 if (set ) {
847+ new -> non_child_axis = set -> non_child_axis ;
847848 new -> ctx = set -> ctx ;
848849 new -> cur_node = set -> cur_node ;
849850 new -> root_type = set -> root_type ;
@@ -5613,6 +5614,7 @@ moveto_root(struct lyxp_set *set, uint32_t options)
56135614 set -> type = LYXP_SET_NODE_SET ;
56145615 set -> used = 0 ;
56155616 set_insert_node (set , NULL , 0 , set -> root_type , 0 );
5617+ set -> non_child_axis = 0 ;
56165618 }
56175619
56185620 return LY_SUCCESS ;
@@ -6026,6 +6028,7 @@ moveto_node(struct lyxp_set *set, const struct lys_module *moveto_mod, const cha
60266028 case LYXP_AXIS_PARENT :
60276029 case LYXP_AXIS_PRECEDING :
60286030 case LYXP_AXIS_PRECEDING_SIBLING :
6031+ result .non_child_axis = 1 ;
60296032 if (set_dup_node_check (& result , iter , iter_type , -1 )) {
60306033 continue ;
60316034 }
@@ -6050,8 +6053,12 @@ moveto_node(struct lyxp_set *set, const struct lys_module *moveto_mod, const cha
60506053 * set = result ;
60516054 result .type = LYXP_SET_NUMBER ;
60526055
6053- /* sort the final set */
6054- set_sort (set );
6056+ /* sort the final set if the document order could have been broken */
6057+ if (set -> non_child_axis ) {
6058+ set_sort (set );
6059+ } else {
6060+ assert (!set_sort (set ));
6061+ }
60556062
60566063cleanup :
60576064 lyxp_set_free_content (& result );
@@ -6756,6 +6763,7 @@ moveto_node_alldesc_child(struct lyxp_set *set, const struct lys_module *moveto_
67566763 ret_set .ctx_size = set -> ctx_size ;
67576764 lyxp_set_free_content (set );
67586765 memcpy (set , & ret_set , sizeof * set );
6766+ assert (!set_sort (set ));
67596767
67606768 return LY_SUCCESS ;
67616769}
0 commit comments