summaryrefslogtreecommitdiffstats
path: root/openpgp/src/serialize/partial_body.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-06-19 13:05:42 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-06-19 13:26:08 +0200
commit476ddfa01a7366358a257e23a18fe402c98f900f (patch)
treef376dd0d1bb974458e66f8c0132d3ebb87029e48 /openpgp/src/serialize/partial_body.rs
parent41faec9e09a0f5b613e815a3b6b4704afb330d8c (diff)
openpgp: Express log2 using the `u32::leading_zeros()` intrinsic.
Diffstat (limited to 'openpgp/src/serialize/partial_body.rs')
-rw-r--r--openpgp/src/serialize/partial_body.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/openpgp/src/serialize/partial_body.rs b/openpgp/src/serialize/partial_body.rs
index 0d1ba87a..a1df796a 100644
--- a/openpgp/src/serialize/partial_body.rs
+++ b/openpgp/src/serialize/partial_body.rs
@@ -13,15 +13,12 @@ use super::{writer, write_byte, Serialize};
// Compute the log2 of an integer. (This is simply the most
// significant bit.) Note: log2(0) = -Inf, but this function returns
// log2(0) as 0 (which is the closest number that we can represent).
-fn log2(mut x: u32) -> usize {
- for i in 0..32 {
- x /= 2;
- if x == 0 {
- return i;
- }
+fn log2(x: u32) -> usize {
+ if x == 0 {
+ 0
+ } else {
+ 31 - x.leading_zeros() as usize
}
-
- return 31;
}
#[test]