@@ -455,39 +455,32 @@ map_load_line(map_t *map, const char *line, size_t line_id)
455455static int
456456map_sort_fn (const void * p1 , const void * p2 )
457457{
458- struct map_rec * rec1 = * (struct map_rec * * ) p1 ;
459- struct map_rec * rec2 = * (struct map_rec * * ) p2 ;
458+ const struct map_ipfix_s * ipfix1 = & ( * (struct map_rec * * ) p1 ) -> ipfix ;
459+ const struct map_ipfix_s * ipfix2 = & ( * (struct map_rec * * ) p2 ) -> ipfix ;
460460
461- if (rec1 -> ipfix .source != rec2 -> ipfix .source ) {
462- return (rec1 -> ipfix .source < rec2 -> ipfix .source ) ? (-1 ) : 1 ;
463- }
464-
465- // Primary sort by PEN
466- if (rec1 -> ipfix .en != rec2 -> ipfix .en ) {
467- return (rec1 -> ipfix .en < rec2 -> ipfix .en ) ? (-1 ) : 1 ;
468- }
469-
470- // Secondary sort by ID
471- if (rec1 -> ipfix .id != rec2 -> ipfix .id ) {
472- return (rec1 -> ipfix .id < rec2 -> ipfix .id ) ? (-1 ) : 1 ;
473- }
461+ while (ipfix1 && ipfix2 ) {
462+ if (ipfix1 -> source != ipfix2 -> source ) {
463+ return (ipfix1 -> source < ipfix2 -> source ) ? (-1 ) : 1 ;
464+ }
474465
475- // TODO: better and more readable code
476- // TODO: check all elements in linked list
477- if (rec1 -> ipfix .next != NULL && rec2 -> ipfix .next != NULL ) {
478466 // Primary sort by PEN
479- if (rec1 -> ipfix . next -> en != rec2 -> ipfix . next -> en ) {
480- return (rec1 -> ipfix . next -> en < rec2 -> ipfix . next -> en ) ? (-1 ) : 1 ;
467+ if (ipfix1 -> en != ipfix2 -> en ) {
468+ return (ipfix1 -> en < ipfix2 -> en ) ? (-1 ) : 1 ;
481469 }
482470
483471 // Secondary sort by ID
484- if (rec1 -> ipfix . next -> id != rec2 -> ipfix . next -> id ) {
485- return (rec1 -> ipfix . next -> id < rec2 -> ipfix . next -> id ) ? (-1 ) : 1 ;
472+ if (ipfix1 -> id != ipfix2 -> id ) {
473+ return (ipfix1 -> id < ipfix2 -> id ) ? (-1 ) : 1 ;
486474 }
487- } else if (rec1 -> ipfix .next != NULL ) {
488- return -1 ;
489- } else if (rec2 -> ipfix .next != NULL ) {
490- return 1 ;
475+
476+ ipfix1 = ipfix1 -> next ;
477+ ipfix2 = ipfix2 -> next ;
478+ }
479+
480+ if (ipfix1 -> next ) {
481+ return -1 ;
482+ } else if (ipfix2 -> next ) {
483+ return 1 ;
491484 }
492485
493486 return 0 ;
0 commit comments