diff --git a/protobuf/src/varint/encode.rs b/protobuf/src/varint/encode.rs index eb9fc2d03..4d3e4ef67 100644 --- a/protobuf/src/varint/encode.rs +++ b/protobuf/src/varint/encode.rs @@ -92,12 +92,10 @@ pub(crate) fn encode_varint32(mut value: u32, buf: &mut [MaybeUninit]) -> us /// Encoded size of u64 value. #[inline] pub(crate) fn encoded_varint64_len(value: u64) -> usize { - if value == 0 { - 1 - } else { - let significant_bits = 64 - value.leading_zeros(); - (significant_bits + 6) as usize / 7 - } + // Bitwise-or'ing by 1 allows the `value = zero` case to work without + // affecting other cases. + let significant_bits = 64 - (value | 1).leading_zeros(); + (significant_bits + 6) as usize / 7 } #[cfg(test)]