about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2019-09-17 16:48:21 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2019-09-19 06:35:11 +1000
commit82e5c6ee6597e7d8926b4f2fea89d02d77f978d4 (patch)
treefae2f2ad95f37b8fdf235913a342d5fabf80be50
parent7f6e160875f375bb71d1ae761cb5cab8f0b02e19 (diff)
downloadrust-82e5c6ee6597e7d8926b4f2fea89d02d77f978d4.tar.gz
rust-82e5c6ee6597e7d8926b4f2fea89d02d77f978d4.zip
Use explicit iteration instead of `all()` in `process_obligation()`.
Amazingly enough, this is a 3.5% instruction count win on `keccak`.
-rw-r--r--src/librustc/traits/fulfill.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs
index 4494c034d51..5eaaeca82f2 100644
--- a/src/librustc/traits/fulfill.rs
+++ b/src/librustc/traits/fulfill.rs
@@ -256,15 +256,22 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
         &mut self,
         pending_obligation: &mut Self::Obligation,
     ) -> ProcessResult<Self::Obligation, Self::Error> {
-        // if we were stalled on some unresolved variables, first check
+        // If we were stalled on some unresolved variables, first check
         // whether any of them have been resolved; if not, don't bother
         // doing more work yet
         if !pending_obligation.stalled_on.is_empty() {
-            if pending_obligation.stalled_on.iter().all(|&ty| {
+            let mut changed = false;
+            // This `for` loop was once a call to `all()`, but this lower-level
+            // form was a perf win. See #64545 for details.
+            for &ty in &pending_obligation.stalled_on {
                 // Use the force-inlined variant of shallow_resolve() because this code is hot.
                 let resolved = ShallowResolver::new(self.selcx.infcx()).inlined_shallow_resolve(ty);
-                resolved == ty // nothing changed here
-            }) {
+                if resolved != ty {
+                    changed = true;
+                    break;
+                }
+            }
+            if !changed {
                 debug!("process_predicate: pending obligation {:?} still stalled on {:?}",
                        self.selcx.infcx()
                            .resolve_vars_if_possible(&pending_obligation.obligation),