igmp: Optimize the implementation of igmp_start_timer

When LWIP_RAND is defined, calling LWIP_RAND() is not necessary if max_time <= 2
because group->timer will be set to 1 anyway.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
This commit is contained in:
Axel Lin 2015-11-30 09:27:31 +08:00 committed by Dirk Ziegelmeier
parent 2562d637cd
commit 2e56f2d780

View File

@ -719,23 +719,16 @@ igmp_timeout(struct igmp_group *group)
static void
igmp_start_timer(struct igmp_group *group, u8_t max_time)
{
/* ensure the input value is > 0 */
#ifdef LWIP_RAND
if (max_time == 0) {
max_time = 1;
}
/* ensure the random value is > 0 */
group->timer = (LWIP_RAND() % max_time);
if (group->timer == 0) {
group->timer = 1;
}
group->timer = max_time > 2 ? (LWIP_RAND() % max_time) : 1;
#else /* LWIP_RAND */
/* ATTENTION: use this only if absolutely necessary! */
group->timer = max_time / 2;
#endif /* LWIP_RAND */
if (group->timer == 0) {
group->timer = 1;
}
#endif /* LWIP_RAND */
}
/**