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:
parent
2a71115261
commit
99fd9cb697
1 changed files with 4 additions and 7 deletions
|
@ -665,15 +665,12 @@ impl Align {
|
||||||
format!("`{}` is too large", align)
|
format!("`{}` is too large", align)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut bytes = align;
|
let tz = align.trailing_zeros();
|
||||||
let mut pow2: u8 = 0;
|
if align != (1 << tz) {
|
||||||
while (bytes & 1) == 0 {
|
|
||||||
pow2 += 1;
|
|
||||||
bytes >>= 1;
|
|
||||||
}
|
|
||||||
if bytes != 1 {
|
|
||||||
return Err(not_power_of_2(align));
|
return Err(not_power_of_2(align));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pow2 = tz as u8;
|
||||||
if pow2 > Self::MAX.pow2 {
|
if pow2 > Self::MAX.pow2 {
|
||||||
return Err(too_large(align));
|
return Err(too_large(align));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue