Skip to content

Commit

Permalink
Simplify bits_for_tags impl
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Apr 20, 2023
1 parent 7cfecf2 commit ad8c7b6
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions compiler/rustc_data_structures/src/tagged_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ pub const fn bits_for_tags(mut tags: &[usize]) -> u32 {
while let &[tag, ref rest @ ..] = tags {
tags = rest;

let b = bits_for_tag(tag);
// bits required to represent `tag`,
// position of the most significant 1
let b = usize::BITS - tag.leading_zeros();
if b > bits {
bits = b;
}
Expand All @@ -164,18 +166,6 @@ pub const fn bits_for_tags(mut tags: &[usize]) -> u32 {
bits
}

/// Returns `(size_of::<usize>() * 8) - tag.leading_zeros()`
const fn bits_for_tag(mut tag: usize) -> u32 {
let mut bits = 0;

while tag > 0 {
bits += 1;
tag >>= 1;
}

bits
}

unsafe impl<T: ?Sized + Aligned> Pointer for Box<T> {
const BITS: u32 = bits_for::<Self::Target>();

Expand Down

0 comments on commit ad8c7b6

Please sign in to comment.