diff options
author | Sunil Nimmagadda <sunil@nimmagadda.net> | 2024-11-24 10:10:33 +0530 |
---|---|---|
committer | Sunil Nimmagadda <sunil@nimmagadda.net> | 2024-11-24 10:10:33 +0530 |
commit | f2f82afcc47ecf2895d6292751309c7c3a8a8e65 (patch) | |
tree | d3c1e42868c8205c06d0490548b7735da793b734 | |
parent | dcada8f40671b54f10bff7f0f8dd5a9240321d74 (diff) |
Unroll loop, atmost two iterations required.
-rw-r--r-- | src/vrrpv2.rs | 5 |
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) } |