From 9198ad056dd9776016bc8b702e12aba43f2badb0 Mon Sep 17 00:00:00 2001 From: lemoer Date: Thu, 1 Dec 2016 01:06:44 +0100 Subject: [PATCH] respondd: append interface infos at the head of the list This avoids walking to the end. --- net/respondd/src/respondd.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/net/respondd/src/respondd.c b/net/respondd/src/respondd.c index 4335bc6..3be8731 100644 --- a/net/respondd/src/respondd.c +++ b/net/respondd/src/respondd.c @@ -621,13 +621,14 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - struct interface_delay_info **pos = &if_delay_info_list; - // walk to the end of the list - for(; *pos; pos = &((*pos)->next)) {} - *pos = malloc(sizeof(*if_delay_info_list)); - (*pos)->ifindex = last_ifindex; - (*pos)->max_multicast_delay = max_multicast_delay; - (*pos)->next = NULL; + // insert the interface delay info at the beginning of the list + struct interface_delay_info **head = &if_delay_info_list; + struct interface_delay_info *old_head = if_delay_info_list; + + *head = malloc(sizeof(*if_delay_info_list)); + (*head)->ifindex = last_ifindex; + (*head)->max_multicast_delay = max_multicast_delay; + (*head)->next = old_head; break;