diff options
| author | The rustc-dev-guide Cronjob Bot <github-actions@github.com> | 2025-06-09 04:09:17 +0000 |
|---|---|---|
| committer | The rustc-dev-guide Cronjob Bot <github-actions@github.com> | 2025-06-09 04:09:17 +0000 |
| commit | 7565e75591c2ef184bc7a359b3a436a62d45358a (patch) | |
| tree | 84784da83b710a97f9944b753c9d7717e37b631b /compiler/rustc_data_structures/src/vec_cache.rs | |
| parent | f598bbd66b8e0cf5ac1adf0ff6147baa7601a731 (diff) | |
| parent | c31cccb7b5cc098b1a8c1794ed38d7fdbec0ccb0 (diff) | |
| download | rust-7565e75591c2ef184bc7a359b3a436a62d45358a.tar.gz rust-7565e75591c2ef184bc7a359b3a436a62d45358a.zip | |
Merge from rustc
Diffstat (limited to 'compiler/rustc_data_structures/src/vec_cache.rs')
| -rw-r--r-- | compiler/rustc_data_structures/src/vec_cache.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/compiler/rustc_data_structures/src/vec_cache.rs b/compiler/rustc_data_structures/src/vec_cache.rs index 2ff60ab7f36..3b448c056b7 100644 --- a/compiler/rustc_data_structures/src/vec_cache.rs +++ b/compiler/rustc_data_structures/src/vec_cache.rs @@ -68,22 +68,22 @@ impl SlotIndex { // slots (see `slot_index_exhaustive` in tests). #[inline] const fn from_index(idx: u32) -> Self { - let mut bucket = match idx.checked_ilog2() { - Some(x) => x as usize, - None => 0, - }; - let entries; - let running_sum; - if bucket <= 11 { - entries = 1 << 12; - running_sum = 0; - bucket = 0; - } else { - entries = 1 << bucket; - running_sum = entries; - bucket = bucket - 11; + const FIRST_BUCKET_SHIFT: usize = 12; + if idx < (1 << FIRST_BUCKET_SHIFT) { + return SlotIndex { + bucket_idx: 0, + entries: 1 << FIRST_BUCKET_SHIFT, + index_in_bucket: idx as usize, + }; + } + // SAFETY: We already ruled out idx 0, so `checked_ilog2` can't return `None`. + let bucket = unsafe { idx.checked_ilog2().unwrap_unchecked() as usize }; + let entries = 1 << bucket; + SlotIndex { + bucket_idx: bucket - FIRST_BUCKET_SHIFT + 1, + entries, + index_in_bucket: idx as usize - entries, } - SlotIndex { bucket_idx: bucket, entries, index_in_bucket: idx as usize - running_sum } } // SAFETY: Buckets must be managed solely by functions here (i.e., get/put on SlotIndex) and |
