@@ -49,7 +49,7 @@ impl<T> Sharded<T> {
49
49
match self {
50
50
Self :: Single ( single) => & single,
51
51
#[ cfg( parallel_compiler) ]
52
- Self :: Shards ( shards ) => self . get_shard_by_hash ( make_hash ( _val) ) ,
52
+ Self :: Shards ( .. ) => self . get_shard_by_hash ( make_hash ( _val) ) ,
53
53
}
54
54
}
55
55
@@ -70,21 +70,20 @@ impl<T> Sharded<T> {
70
70
}
71
71
}
72
72
73
- #[ inline]
74
- fn count ( & self ) -> usize {
73
+ pub fn lock_shards ( & self ) -> Vec < LockGuard < ' _ , T > > {
75
74
match self {
76
- Self :: Single ( .. ) => 1 ,
75
+ Self :: Single ( single ) => vec ! [ single . lock ( ) ] ,
77
76
#[ cfg( parallel_compiler) ]
78
- Self :: Shards ( .. ) => SHARDS ,
77
+ Self :: Shards ( shards ) => shards . iter ( ) . map ( |shard| shard . 0 . lock ( ) ) . collect ( ) ,
79
78
}
80
79
}
81
80
82
- pub fn lock_shards ( & self ) -> Vec < LockGuard < ' _ , T > > {
83
- ( 0 ..self . count ( ) ) . map ( |i| self . get_shard_by_index ( i) . lock ( ) ) . collect ( )
84
- }
85
-
86
81
pub fn try_lock_shards ( & self ) -> Option < Vec < LockGuard < ' _ , T > > > {
87
- ( 0 ..self . count ( ) ) . map ( |i| self . get_shard_by_index ( i) . try_lock ( ) ) . collect ( )
82
+ match self {
83
+ Self :: Single ( single) => Some ( vec ! [ single. try_lock( ) ?] ) ,
84
+ #[ cfg( parallel_compiler) ]
85
+ Self :: Shards ( shards) => shards. iter ( ) . map ( |shard| shard. 0 . try_lock ( ) ) . collect ( ) ,
86
+ }
88
87
}
89
88
}
90
89
0 commit comments