File tree 1 file changed +1
-19
lines changed
compiler/rustc_data_structures/src
1 file changed +1
-19
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: fx:: { FxHashMap , FxHasher } ;
2
2
use crate :: sync:: { Lock , LockGuard } ;
3
- use smallvec:: SmallVec ;
4
3
use std:: borrow:: Borrow ;
5
4
use std:: collections:: hash_map:: RawEntryMut ;
6
5
use std:: hash:: { Hash , Hasher } ;
@@ -37,24 +36,7 @@ impl<T: Default> Default for Sharded<T> {
37
36
impl < T > Sharded < T > {
38
37
#[ inline]
39
38
pub fn new ( mut value : impl FnMut ( ) -> T ) -> Self {
40
- // Create a vector of the values we want
41
- let mut values: SmallVec < [ _ ; SHARDS ] > =
42
- ( 0 ..SHARDS ) . map ( |_| CacheAligned ( Lock :: new ( value ( ) ) ) ) . collect ( ) ;
43
-
44
- // Create an uninitialized array
45
- let mut shards: mem:: MaybeUninit < [ CacheAligned < Lock < T > > ; SHARDS ] > =
46
- mem:: MaybeUninit :: uninit ( ) ;
47
-
48
- unsafe {
49
- // Copy the values into our array
50
- let first = shards. as_mut_ptr ( ) as * mut CacheAligned < Lock < T > > ;
51
- values. as_ptr ( ) . copy_to_nonoverlapping ( first, SHARDS ) ;
52
-
53
- // Ignore the content of the vector
54
- values. set_len ( 0 ) ;
55
-
56
- Sharded { shards : shards. assume_init ( ) }
57
- }
39
+ Sharded { shards : [ ( ) ; SHARDS ] . map ( |( ) | CacheAligned ( Lock :: new ( value ( ) ) ) ) }
58
40
}
59
41
60
42
/// The shard is selected by hashing `val` with `FxHasher`.
You can’t perform that action at this time.
0 commit comments