about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-04-20 19:24:04 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-04-20 19:54:10 +0000
commitad8c7b6705d94bdf9293fbfe0c4d386d5f7e81a2 (patch)
tree63e0af38da3a549ddd143eabee22cfc8a596cd33
parent7cfecf26f77f0d2c3d83be946d4da6ab997c939e (diff)
downloadrust-ad8c7b6705d94bdf9293fbfe0c4d386d5f7e81a2.tar.gz
rust-ad8c7b6705d94bdf9293fbfe0c4d386d5f7e81a2.zip
Simplify `bits_for_tags` impl
-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>();