From f458b112f88e1dbcd5072733c79e25328f9f24f9 Mon Sep 17 00:00:00 2001 From: John Kåre Alsaker Date: Thu, 17 Aug 2023 11:07:50 +0200 Subject: Optimize `lock_shards` --- compiler/rustc_query_system/src/query/caches.rs | 6 ++---- compiler/rustc_query_system/src/query/plumbing.rs | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'compiler/rustc_query_system') diff --git a/compiler/rustc_query_system/src/query/caches.rs b/compiler/rustc_query_system/src/query/caches.rs index 4ba9d53a92f..a96230fdc94 100644 --- a/compiler/rustc_query_system/src/query/caches.rs +++ b/compiler/rustc_query_system/src/query/caches.rs @@ -70,8 +70,7 @@ where } fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) { - let shards = self.cache.lock_shards(); - for shard in shards.iter() { + for shard in self.cache.lock_shards() { for (k, v) in shard.iter() { f(k, &v.0, v.1); } @@ -160,8 +159,7 @@ where } fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) { - let shards = self.cache.lock_shards(); - for shard in shards.iter() { + for shard in self.cache.lock_shards() { for (k, v) in shard.iter_enumerated() { if let Some(v) = v { f(&k, &v.0, v.1); diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 74b8aaf4f27..e8a22a7c5da 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -50,8 +50,7 @@ where D: DepKind, { pub fn all_inactive(&self) -> bool { - let shards = self.active.lock_shards(); - shards.iter().all(|shard| shard.is_empty()) + self.active.lock_shards().all(|shard| shard.is_empty()) } pub fn try_collect_active_jobs( @@ -64,9 +63,8 @@ where // We use try_lock_shards here since we are called from the // deadlock handler, and this shouldn't be locked. - let shards = self.active.try_lock_shards()?; - for shard in shards.iter() { - for (k, v) in shard.iter() { + for shard in self.active.try_lock_shards() { + for (k, v) in shard?.iter() { if let QueryResult::Started(ref job) = *v { active.push((*k, job.clone())); } -- cgit 1.4.1-3-g733a5