Skip to content

Commit 5563b36

Browse files
committed
Use if SHARDS == 1 in a couple more places.
It's already used in `get_shard_by_value`, doesn't hurt to add it in a couple of related functions for consistency.
1 parent bfb2856 commit 5563b36

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

compiler/rustc_data_structures/src/sharded.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ impl<T> Sharded<T> {
4747

4848
#[inline]
4949
pub fn get_shard_by_hash(&self, hash: u64) -> &Lock<T> {
50-
&self.shards[get_shard_index_by_hash(hash)].0
50+
if SHARDS == 1 { &self.shards[0].0 } else { &self.shards[get_shard_index_by_hash(hash)].0 }
5151
}
5252

5353
#[inline]
5454
pub fn get_shard_by_index(&self, i: usize) -> &Lock<T> {
55-
&self.shards[i].0
55+
if SHARDS == 1 { &self.shards[0].0 } else { &self.shards[i].0 }
5656
}
5757

5858
pub fn lock_shards(&self) -> Vec<LockGuard<'_, T>> {
@@ -142,9 +142,13 @@ fn make_hash<K: Hash + ?Sized>(val: &K) -> u64 {
142142
/// consistently for each `Sharded` instance.
143143
#[inline]
144144
pub fn get_shard_index_by_hash(hash: u64) -> usize {
145-
let hash_len = mem::size_of::<usize>();
146-
// Ignore the top 7 bits as hashbrown uses these and get the next SHARD_BITS highest bits.
147-
// hashbrown also uses the lowest bits, so we can't use those
148-
let bits = (hash >> (hash_len * 8 - 7 - SHARD_BITS)) as usize;
149-
bits % SHARDS
145+
if SHARDS == 1 {
146+
0
147+
} else {
148+
let hash_len = mem::size_of::<usize>();
149+
// Ignore the top 7 bits as hashbrown uses these and get the next SHARD_BITS highest bits.
150+
// hashbrown also uses the lowest bits, so we can't use those
151+
let bits = (hash >> (hash_len * 8 - 7 - SHARD_BITS)) as usize;
152+
bits % SHARDS
153+
}
150154
}

0 commit comments

Comments
 (0)