From f2f82afcc47ecf2895d6292751309c7c3a8a8e65 Mon Sep 17 00:00:00 2001 From: Sunil Nimmagadda Date: Sun, 24 Nov 2024 10:10:33 +0530 Subject: Unroll loop, atmost two iterations required. --- src/vrrpv2.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/vrrpv2.rs b/src/vrrpv2.rs index c9d5031..643d6c3 100644 --- a/src/vrrpv2.rs +++ b/src/vrrpv2.rs @@ -200,9 +200,8 @@ fn checksum(bytes: &[u8]) -> u16 { if !remainder.is_empty() { sum += u32::from(remainder[0]); } - while (sum >> 16) > 0 { - sum = (sum & 0xffff) + (sum >> 16); - } + sum = (sum >> 16) + (sum & 0xffff); + sum += sum >> 16; !(sum as u16) } -- cgit v1.2.3