Skip to content

Commit ad8c7b6

Browse files
committed
Simplify bits_for_tags impl
1 parent 7cfecf2 commit ad8c7b6

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

compiler/rustc_data_structures/src/tagged_ptr.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ pub const fn bits_for_tags(mut tags: &[usize]) -> u32 {
155155
while let &[tag, ref rest @ ..] = tags {
156156
tags = rest;
157157

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

167-
/// Returns `(size_of::<usize>() * 8) - tag.leading_zeros()`
168-
const fn bits_for_tag(mut tag: usize) -> u32 {
169-
let mut bits = 0;
170-
171-
while tag > 0 {
172-
bits += 1;
173-
tag >>= 1;
174-
}
175-
176-
bits
177-
}
178-
179169
unsafe impl<T: ?Sized + Aligned> Pointer for Box<T> {
180170
const BITS: u32 = bits_for::<Self::Target>();
181171

0 commit comments

Comments
 (0)