diff options
| author | fee1-dead <ent3rm4n@gmail.com> | 2023-04-16 19:36:03 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-16 19:36:03 +0800 |
| commit | 38215fb77aca2dcd25277ff7b3093ea56e4e8ffb (patch) | |
| tree | 5dc9736a01770f7fda4378f2e2c949710f998d17 /compiler/rustc_abi/src/lib.rs | |
| parent | 1d30adb06860ae215634d1dd1eaf8ee600ed1347 (diff) | |
| parent | 99fd9cb6971fc68d6865c2e2cf7722030001f609 (diff) | |
| download | rust-38215fb77aca2dcd25277ff7b3093ea56e4e8ffb.tar.gz rust-38215fb77aca2dcd25277ff7b3093ea56e4e8ffb.zip | |
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.
Diffstat (limited to 'compiler/rustc_abi/src/lib.rs')
| -rw-r--r-- | compiler/rustc_abi/src/lib.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index b0c0ee942ea..7a3defd2a5d 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -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)); } |
