Skip to content

Commit 38215fb

Browse files
authored
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.
2 parents 1d30adb + 99fd9cb commit 38215fb

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

compiler/rustc_abi/src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,12 @@ impl Align {
665665
format!("`{}` is too large", align)
666666
}
667667

668-
let mut bytes = align;
669-
let mut pow2: u8 = 0;
670-
while (bytes & 1) == 0 {
671-
pow2 += 1;
672-
bytes >>= 1;
673-
}
674-
if bytes != 1 {
668+
let tz = align.trailing_zeros();
669+
if align != (1 << tz) {
675670
return Err(not_power_of_2(align));
676671
}
672+
673+
let pow2 = tz as u8;
677674
if pow2 > Self::MAX.pow2 {
678675
return Err(too_large(align));
679676
}

0 commit comments

Comments
 (0)