@@ -751,77 +751,38 @@ ly_ctx_get_modules_hash(const struct ly_ctx *ctx)
751751 return ctx -> mod_hash ;
752752}
753753
754- /**
755- * @brief qsort() alphabetical compare of modules.
756- */
757- static int
758- ly_ctx_mod_cmp_cb (const void * ptr1 , const void * ptr2 )
759- {
760- const struct lys_module * mod1 , * mod2 ;
761- int r ;
762-
763- mod1 = * (struct lys_module * * )ptr1 ;
764- mod2 = * (struct lys_module * * )ptr2 ;
765-
766- /* module name */
767- r = strcmp (mod1 -> name , mod2 -> name );
768- if (!r ) {
769- /* revision */
770- if (mod1 -> revision && !mod2 -> revision ) {
771- r = 1 ;
772- } else if (!mod1 -> revision && mod2 -> revision ) {
773- r = -1 ;
774- } else if (mod1 -> revision && mod2 -> revision ) {
775- r = strcmp (mod1 -> revision , mod2 -> revision );
776- }
777- }
778-
779- return r ;
780- }
781-
782754void
783755ly_ctx_new_change (struct ly_ctx * ctx )
784756{
785- uint32_t i , hash = 0 ;
786- const struct lys_module * * mods = NULL ;
757+ const struct lys_module * mod ;
758+ uint32_t i = ly_ctx_internal_modules_count ( ctx ), hash = 0 ;
787759 LY_ARRAY_COUNT_TYPE u ;
788760
789761 /* change counter */
790762 ctx -> change_count ++ ;
791763
792- /* collect modules into an array */
793- mods = malloc (ctx -> modules .count * sizeof * mods );
794- LY_CHECK_ERR_GOTO (!mods , LOGMEM (ctx ), cleanup );
795- memcpy (mods , ctx -> modules .objs , ctx -> modules .count * sizeof * mods );
796-
797- /* sort modules alphabetically */
798- qsort (mods , ctx -> modules .count , sizeof * mods , ly_ctx_mod_cmp_cb );
799-
800- /* calculate module hash */
801- for (i = 0 ; i < ctx -> modules .count ; ++ i ) {
764+ /* module hash */
765+ while ((mod = ly_ctx_get_module_iter (ctx , & i ))) {
802766 /* name */
803- hash = lyht_hash_multi (hash , mods [ i ] -> name , strlen (mods [ i ] -> name ));
767+ hash = lyht_hash_multi (hash , mod -> name , strlen (mod -> name ));
804768
805769 /* revision */
806- if (mods [ i ] -> revision ) {
807- hash = lyht_hash_multi (hash , mods [ i ] -> revision , strlen (mods [ i ] -> revision ));
770+ if (mod -> revision ) {
771+ hash = lyht_hash_multi (hash , mod -> revision , strlen (mod -> revision ));
808772 }
809773
810774 /* enabled features */
811- if (mods [ i ] -> implemented ) {
812- LY_ARRAY_FOR (mods [ i ] -> compiled -> features , u ) {
813- hash = lyht_hash_multi (hash , mods [ i ] -> compiled -> features [u ], strlen (mods [ i ] -> compiled -> features [u ]));
775+ if (mod -> implemented ) {
776+ LY_ARRAY_FOR (mod -> compiled -> features , u ) {
777+ hash = lyht_hash_multi (hash , mod -> compiled -> features [u ], strlen (mod -> compiled -> features [u ]));
814778 }
815779 }
816780
817781 /* imported/implemented */
818- hash = lyht_hash_multi (hash , (char * )& mods [ i ] -> implemented , sizeof mods [ i ] -> implemented );
782+ hash = lyht_hash_multi (hash , (char * )& mod -> implemented , sizeof mod -> implemented );
819783 }
820784
821785 ctx -> mod_hash = lyht_hash_multi (hash , NULL , 0 );
822-
823- cleanup :
824- free (mods );
825786}
826787
827788LIBYANG_API_DEF ly_module_imp_clb
0 commit comments