about summary refs log tree commit diff
path: root/compiler/rustc_query_system
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-08-17 11:07:50 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-08-24 23:29:48 +0200
commitf458b112f88e1dbcd5072733c79e25328f9f24f9 (patch)
tree00de2aa02857f15677694609c05dca09b40c7db7 /compiler/rustc_query_system
parentb74cb78d63879bcca4e8039d45cd1878e0687b2e (diff)
downloadrust-f458b112f88e1dbcd5072733c79e25328f9f24f9.tar.gz
rust-f458b112f88e1dbcd5072733c79e25328f9f24f9.zip
Optimize `lock_shards`
Diffstat (limited to 'compiler/rustc_query_system')
-rw-r--r--compiler/rustc_query_system/src/query/caches.rs6
-rw-r--r--compiler/rustc_query_system/src/query/plumbing.rs8
2 files changed, 5 insertions, 9 deletions
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<Qcx: Copy>(
@@ -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()));
                 }