From 5c1dd6a4c65b9fb9c8628ffc911478855979d6e9 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Sat, 17 Dec 2016 15:06:33 +0100 Subject: [PATCH] Optimization in igmp_remove_group() pointed out by Axel Lin No need to handle special case "first in list" since this is always the allsystems group that shall not be removed --- src/core/ipv4/igmp.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/core/ipv4/igmp.c b/src/core/ipv4/igmp.c index 5ea2fdab..58613d3b 100644 --- a/src/core/ipv4/igmp.c +++ b/src/core/ipv4/igmp.c @@ -295,24 +295,24 @@ static err_t igmp_remove_group(struct netif* netif, struct igmp_group *group) { err_t err = ERR_OK; + struct igmp_group *tmp_group = netif_igmp_data(netif); - /* Is it the first group? */ - if (netif_igmp_data(netif) == group) { - netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_IGMP, group->next); - } else { - /* look for group further down the list */ - struct igmp_group *tmpGroup; - for (tmpGroup = netif_igmp_data(netif); tmpGroup != NULL; tmpGroup = tmpGroup->next) { - if (tmpGroup->next == group) { - tmpGroup->next = group->next; - break; - } - } - /* Group not found in the global igmp_group_list */ - if (tmpGroup == NULL) { - err = ERR_ARG; + /* Skip the first group in the list, it is always the allsystems group added in igmp_start() */ + if(tmp_group != NULL) { + tmp_group = tmp_group->next; + } + + /* look for group further down the list */ + for (; tmp_group != NULL; tmp_group = tmp_group->next) { + if (tmp_group->next == group) { + tmp_group->next = group->next; + break; } } + /* Group not found in the global igmp_group_list */ + if (tmp_group == NULL) { + err = ERR_ARG; + } return err; }