Skip to content

Commit 0823f0c

Browse files
committed
Remove count
1 parent 81220c0 commit 0823f0c

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

compiler/rustc_data_structures/src/sharded.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<T> Sharded<T> {
4949
match self {
5050
Self::Single(single) => &single,
5151
#[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)),
5353
}
5454
}
5555

@@ -70,21 +70,20 @@ impl<T> Sharded<T> {
7070
}
7171
}
7272

73-
#[inline]
74-
fn count(&self) -> usize {
73+
pub fn lock_shards(&self) -> Vec<LockGuard<'_, T>> {
7574
match self {
76-
Self::Single(..) => 1,
75+
Self::Single(single) => vec![single.lock()],
7776
#[cfg(parallel_compiler)]
78-
Self::Shards(..) => SHARDS,
77+
Self::Shards(shards) => shards.iter().map(|shard| shard.0.lock()).collect(),
7978
}
8079
}
8180

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-
8681
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+
}
8887
}
8988
}
9089

0 commit comments

Comments
 (0)