Rollup merge of #110402 - scottmcm:align-tz, r=fee1-dead

Remove the loop in `Align::from_bytes`

Perf is almost certainly irrelevant, but might as well simplify it, since `trailing_zeros` does exactly what's needed.
This commit is contained in:
fee1-dead 2023-04-16 19:36:03 +08:00 committed by GitHub
commit 38215fb77a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -665,15 +665,12 @@ impl Align {
format!("`{}` is too large", align)
}
let mut bytes = align;
let mut pow2: u8 = 0;
while (bytes & 1) == 0 {
pow2 += 1;
bytes >>= 1;
}
if bytes != 1 {
let tz = align.trailing_zeros();
if align != (1 << tz) {
return Err(not_power_of_2(align));
}
let pow2 = tz as u8;
if pow2 > Self::MAX.pow2 {
return Err(too_large(align));
}