diff options
| author | ljedrz <ljedrz@gmail.com> | 2018-09-28 17:32:22 +0200 |
|---|---|---|
| committer | ljedrz <ljedrz@gmail.com> | 2018-09-29 14:57:41 +0200 |
| commit | 999d76812cc2403568a2c5740be3474d5f8fc36f (patch) | |
| tree | d6506c48e39ca337f4695082ac46a7925ea70ff1 | |
| parent | 0e84647e18181ea9aa199d42b3da598eb59ab70c (diff) | |
| download | rust-999d76812cc2403568a2c5740be3474d5f8fc36f.tar.gz rust-999d76812cc2403568a2c5740be3474d5f8fc36f.zip | |
rustc/infer: improve vector allocations
| -rw-r--r-- | src/librustc/infer/canonical/query_result.rs | 71 | ||||
| -rw-r--r-- | src/librustc/infer/opaque_types/mod.rs | 1 |
2 files changed, 37 insertions, 35 deletions
diff --git a/src/librustc/infer/canonical/query_result.rs b/src/librustc/infer/canonical/query_result.rs index 810d3231acd..f70064e0716 100644 --- a/src/librustc/infer/canonical/query_result.rs +++ b/src/librustc/infer/canonical/query_result.rs @@ -310,16 +310,18 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { } // ...also include the other query region constraints from the query. - output_query_region_constraints.reserve(query_result.value.region_constraints.len()); - for r_c in query_result.value.region_constraints.iter() { - let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below - let k1 = substitute_value(self.tcx, &result_subst, &k1); - let r2 = substitute_value(self.tcx, &result_subst, &r2); - if k1 != r2.into() { - output_query_region_constraints - .push(ty::Binder::bind(ty::OutlivesPredicate(k1, r2))); - } - } + output_query_region_constraints.extend( + query_result.value.region_constraints.iter().filter_map(|r_c| { + let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below + let k1 = substitute_value(self.tcx, &result_subst, &k1); + let r2 = substitute_value(self.tcx, &result_subst, &r2); + if k1 != r2.into() { + Some(ty::Binder::bind(ty::OutlivesPredicate(k1, r2))) + } else { + None + } + }) + ); let user_result: R = query_result.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value); @@ -576,31 +578,30 @@ pub fn make_query_outlives<'tcx>( assert!(verifys.is_empty()); assert!(givens.is_empty()); - let mut outlives: Vec<_> = constraints - .into_iter() - .map(|(k, _)| match *k { - // Swap regions because we are going from sub (<=) to outlives - // (>=). - Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate( - tcx.mk_region(ty::ReVar(v2)).into(), - tcx.mk_region(ty::ReVar(v1)), - ), - Constraint::VarSubReg(v1, r2) => { - ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1))) - } - Constraint::RegSubVar(r1, v2) => { - ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1) - } - Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1), - }) - .map(ty::Binder::dummy) // no bound regions in the code above - .collect(); - - outlives.extend( - outlives_obligations - .map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r)) - .map(ty::Binder::dummy), // no bound regions in the code above - ); + let outlives: Vec<_> = constraints + .into_iter() + .map(|(k, _)| match *k { + // Swap regions because we are going from sub (<=) to outlives + // (>=). + Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate( + tcx.mk_region(ty::ReVar(v2)).into(), + tcx.mk_region(ty::ReVar(v1)), + ), + Constraint::VarSubReg(v1, r2) => { + ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1))) + } + Constraint::RegSubVar(r1, v2) => { + ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1) + } + Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1), + }) + .map(ty::Binder::dummy) // no bound regions in the code above + .chain( + outlives_obligations + .map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r)) + .map(ty::Binder::dummy), // no bound regions in the code above + ) + .collect(); outlives } diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 88d37574267..d365992aef5 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -803,6 +803,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> { ); debug!("instantiate_opaque_types: ty_var={:?}", ty_var); + self.obligations.reserve(bounds.predicates.len()); for predicate in bounds.predicates { // Change the predicate to refer to the type variable, // which will be the concrete type instead of the opaque type. |
