diff options
| author | Josh Triplett <josh@joshtriplett.org> | 2025-06-05 16:57:59 -0700 |
|---|---|---|
| committer | Josh Triplett <josh@joshtriplett.org> | 2025-06-05 16:57:59 -0700 |
| commit | 8a56ed4c89d38618e065f7d9ec6be0390fdabe31 (patch) | |
| tree | 2268bbedce1dfc9c87273ee212a07a94b25bc322 /compiler/rustc_data_structures/src | |
| parent | 9837c3c3f8accf763704cc56e2b13398e86db282 (diff) | |
| download | rust-8a56ed4c89d38618e065f7d9ec6be0390fdabe31.tar.gz rust-8a56ed4c89d38618e065f7d9ec6be0390fdabe31.zip | |
`SlotIndex::from_index`: Factor out a constant for the first bucket size
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/vec_cache.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/rustc_data_structures/src/vec_cache.rs b/compiler/rustc_data_structures/src/vec_cache.rs index cc6973fb42e..3b448c056b7 100644 --- a/compiler/rustc_data_structures/src/vec_cache.rs +++ b/compiler/rustc_data_structures/src/vec_cache.rs @@ -68,13 +68,22 @@ impl SlotIndex { // slots (see `slot_index_exhaustive` in tests). #[inline] const fn from_index(idx: u32) -> Self { - if idx < 4096 { - return SlotIndex { bucket_idx: 0, entries: 4096, index_in_bucket: idx as usize }; + 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 - 11, entries, index_in_bucket: idx as usize - entries } + SlotIndex { + bucket_idx: bucket - FIRST_BUCKET_SHIFT + 1, + entries, + index_in_bucket: idx as usize - entries, + } } // SAFETY: Buckets must be managed solely by functions here (i.e., get/put on SlotIndex) and |
