Skip to content

Commit

Permalink
Remove count
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Aug 16, 2023
1 parent 81220c0 commit 0823f0c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions compiler/rustc_data_structures/src/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<T> Sharded<T> {
match self {
Self::Single(single) => &single,
#[cfg(parallel_compiler)]
Self::Shards(shards) => self.get_shard_by_hash(make_hash(_val)),
Self::Shards(..) => self.get_shard_by_hash(make_hash(_val)),
}
}

Expand All @@ -70,21 +70,20 @@ impl<T> Sharded<T> {
}
}

#[inline]
fn count(&self) -> usize {
pub fn lock_shards(&self) -> Vec<LockGuard<'_, T>> {
match self {
Self::Single(..) => 1,
Self::Single(single) => vec![single.lock()],
#[cfg(parallel_compiler)]
Self::Shards(..) => SHARDS,
Self::Shards(shards) => shards.iter().map(|shard| shard.0.lock()).collect(),
}
}

pub fn lock_shards(&self) -> Vec<LockGuard<'_, T>> {
(0..self.count()).map(|i| self.get_shard_by_index(i).lock()).collect()
}

pub fn try_lock_shards(&self) -> Option<Vec<LockGuard<'_, T>>> {
(0..self.count()).map(|i| self.get_shard_by_index(i).try_lock()).collect()
match self {
Self::Single(single) => Some(vec![single.try_lock()?]),
#[cfg(parallel_compiler)]
Self::Shards(shards) => shards.iter().map(|shard| shard.0.try_lock()).collect(),
}
}
}

Expand Down

0 comments on commit 0823f0c

Please sign in to comment.