Remove count

This commit is contained in:
John Kåre Alsaker 2023-08-16 10:44:32 +02:00
parent 81220c0ace
commit 0823f0c32b

View File

@ -49,7 +49,7 @@ pub fn get_shard_by_value<K: Hash + ?Sized>(&self, _val: &K) -> &Lock<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)),
}
}
@ -70,21 +70,20 @@ pub fn get_shard_by_index(&self, _i: usize) -> &Lock<T> {
}
}
#[inline]
fn count(&self) -> usize {
match self {
Self::Single(..) => 1,
#[cfg(parallel_compiler)]
Self::Shards(..) => SHARDS,
}
}
pub fn lock_shards(&self) -> Vec<LockGuard<'_, T>> {
(0..self.count()).map(|i| self.get_shard_by_index(i).lock()).collect()
match self {
Self::Single(single) => vec![single.lock()],
#[cfg(parallel_compiler)]
Self::Shards(shards) => shards.iter().map(|shard| shard.0.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(),
}
}
}