about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_data_structures/src/tagged_ptr.rs16
1 files changed, 3 insertions, 13 deletions
diff --git a/compiler/rustc_data_structures/src/tagged_ptr.rs b/compiler/rustc_data_structures/src/tagged_ptr.rs
index a25046986cc..2914eece679 100644
--- a/compiler/rustc_data_structures/src/tagged_ptr.rs
+++ b/compiler/rustc_data_structures/src/tagged_ptr.rs
@@ -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;
         }
@@ -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>();