diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2018-06-08 17:21:07 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-08 17:21:07 -0600 |
| commit | 8ac351c2091973a4b7ce3c0428569bf5486e9a72 (patch) | |
| tree | b74bea9ae3d0d3ac9efaebfa5db7c52ee19bade6 /src/librustc_data_structures | |
| parent | 898bb78024e618f43375564bf59655acdd7ddbc3 (diff) | |
| parent | b0440d359b0dab992e8f01d63523799a72c81285 (diff) | |
| download | rust-8ac351c2091973a4b7ce3c0428569bf5486e9a72.tar.gz rust-8ac351c2091973a4b7ce3c0428569bf5486e9a72.zip | |
Rollup merge of #51412 - nnethercote:pending_obligations, r=estebank
Avoid useless Vec clones in pending_obligations(). The only instance of `ObligationForest` in use has an obligation type of `PendingPredicateObligation`, which contains a `PredicateObligation` and a `Vec<Ty>`. `FulfillmentContext::pending_obligations()` calls `ObligationForest::pending_obligations()`, which clones all the `PendingPredicateObligation`s. But the `Vec<Ty>` field of those cloned obligations is never touched. This patch changes `ObligationForest::pending_obligations()` to `map_pending_obligations` -- which gives callers control about which part of the obligation to clone -- and takes advantage of the change to avoid cloning the `Vec<Ty>`. The change speeds up runs of a few rustc-perf benchmarks, the best by 1%.
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/obligation_forest/mod.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/librustc_data_structures/obligation_forest/mod.rs b/src/librustc_data_structures/obligation_forest/mod.rs index 612f44f09cf..c3934c4e1b8 100644 --- a/src/librustc_data_structures/obligation_forest/mod.rs +++ b/src/librustc_data_structures/obligation_forest/mod.rs @@ -229,13 +229,13 @@ impl<O: ForestObligation> ObligationForest<O> { } /// Returns the set of obligations that are in a pending state. - pub fn pending_obligations(&self) -> Vec<O> - where O: Clone + pub fn map_pending_obligations<P, F>(&self, f: F) -> Vec<P> + where F: Fn(&O) -> P { self.nodes .iter() .filter(|n| n.state.get() == NodeState::Pending) - .map(|n| n.obligation.clone()) + .map(|n| f(&n.obligation)) .collect() } |
