File tree 1 file changed +11
-7
lines changed
compiler/rustc_data_structures/src
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -47,12 +47,12 @@ impl<T> Sharded<T> {
47
47
48
48
#[ inline]
49
49
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 }
51
51
}
52
52
53
53
#[ inline]
54
54
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 }
56
56
}
57
57
58
58
pub fn lock_shards ( & self ) -> Vec < LockGuard < ' _ , T > > {
@@ -142,9 +142,13 @@ fn make_hash<K: Hash + ?Sized>(val: &K) -> u64 {
142
142
/// consistently for each `Sharded` instance.
143
143
#[ inline]
144
144
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
+ }
150
154
}
You can’t perform that action at this time.
0 commit comments