summaryrefslogtreecommitdiff
path: root/src/vrrpv2.rs
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2024-11-24 10:10:33 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2024-11-24 10:10:33 +0530
commitf2f82afcc47ecf2895d6292751309c7c3a8a8e65 (patch)
treed3c1e42868c8205c06d0490548b7735da793b734 /src/vrrpv2.rs
parentdcada8f40671b54f10bff7f0f8dd5a9240321d74 (diff)
Unroll loop, atmost two iterations required.
Diffstat (limited to 'src/vrrpv2.rs')
-rw-r--r--src/vrrpv2.rs5
1 files 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)
}