File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
compiler/rustc_data_structures/src Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -68,13 +68,22 @@ impl SlotIndex {
68
68
// slots (see `slot_index_exhaustive` in tests).
69
69
#[ inline]
70
70
const fn from_index ( idx : u32 ) -> Self {
71
- if idx < 4096 {
72
- return SlotIndex { bucket_idx : 0 , entries : 4096 , index_in_bucket : idx as usize } ;
71
+ const FIRST_BUCKET_SHIFT : usize = 12 ;
72
+ if idx < ( 1 << FIRST_BUCKET_SHIFT ) {
73
+ return SlotIndex {
74
+ bucket_idx : 0 ,
75
+ entries : 1 << FIRST_BUCKET_SHIFT ,
76
+ index_in_bucket : idx as usize ,
77
+ } ;
73
78
}
74
79
// SAFETY: We already ruled out idx 0, so `checked_ilog2` can't return `None`.
75
80
let bucket = unsafe { idx. checked_ilog2 ( ) . unwrap_unchecked ( ) as usize } ;
76
81
let entries = 1 << bucket;
77
- SlotIndex { bucket_idx : bucket - 11 , entries, index_in_bucket : idx as usize - entries }
82
+ SlotIndex {
83
+ bucket_idx : bucket - FIRST_BUCKET_SHIFT + 1 ,
84
+ entries,
85
+ index_in_bucket : idx as usize - entries,
86
+ }
78
87
}
79
88
80
89
// SAFETY: Buckets must be managed solely by functions here (i.e., get/put on SlotIndex) and
You can’t perform that action at this time.
0 commit comments