Skip to content

Commit 999d768

Browse files
committed
rustc/infer: improve vector allocations
1 parent 0e84647 commit 999d768

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

src/librustc/infer/canonical/query_result.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,18 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
310310
}
311311

312312
// ...also include the other query region constraints from the query.
313-
output_query_region_constraints.reserve(query_result.value.region_constraints.len());
314-
for r_c in query_result.value.region_constraints.iter() {
315-
let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below
316-
let k1 = substitute_value(self.tcx, &result_subst, &k1);
317-
let r2 = substitute_value(self.tcx, &result_subst, &r2);
318-
if k1 != r2.into() {
319-
output_query_region_constraints
320-
.push(ty::Binder::bind(ty::OutlivesPredicate(k1, r2)));
321-
}
322-
}
313+
output_query_region_constraints.extend(
314+
query_result.value.region_constraints.iter().filter_map(|r_c| {
315+
let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below
316+
let k1 = substitute_value(self.tcx, &result_subst, &k1);
317+
let r2 = substitute_value(self.tcx, &result_subst, &r2);
318+
if k1 != r2.into() {
319+
Some(ty::Binder::bind(ty::OutlivesPredicate(k1, r2)))
320+
} else {
321+
None
322+
}
323+
})
324+
);
323325

324326
let user_result: R =
325327
query_result.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
@@ -576,31 +578,30 @@ pub fn make_query_outlives<'tcx>(
576578
assert!(verifys.is_empty());
577579
assert!(givens.is_empty());
578580

579-
let mut outlives: Vec<_> = constraints
580-
.into_iter()
581-
.map(|(k, _)| match *k {
582-
// Swap regions because we are going from sub (<=) to outlives
583-
// (>=).
584-
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
585-
tcx.mk_region(ty::ReVar(v2)).into(),
586-
tcx.mk_region(ty::ReVar(v1)),
587-
),
588-
Constraint::VarSubReg(v1, r2) => {
589-
ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1)))
590-
}
591-
Constraint::RegSubVar(r1, v2) => {
592-
ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
593-
}
594-
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
595-
})
596-
.map(ty::Binder::dummy) // no bound regions in the code above
597-
.collect();
598-
599-
outlives.extend(
600-
outlives_obligations
601-
.map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r))
602-
.map(ty::Binder::dummy), // no bound regions in the code above
603-
);
581+
let outlives: Vec<_> = constraints
582+
.into_iter()
583+
.map(|(k, _)| match *k {
584+
// Swap regions because we are going from sub (<=) to outlives
585+
// (>=).
586+
Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
587+
tcx.mk_region(ty::ReVar(v2)).into(),
588+
tcx.mk_region(ty::ReVar(v1)),
589+
),
590+
Constraint::VarSubReg(v1, r2) => {
591+
ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1)))
592+
}
593+
Constraint::RegSubVar(r1, v2) => {
594+
ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
595+
}
596+
Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
597+
})
598+
.map(ty::Binder::dummy) // no bound regions in the code above
599+
.chain(
600+
outlives_obligations
601+
.map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r))
602+
.map(ty::Binder::dummy), // no bound regions in the code above
603+
)
604+
.collect();
604605

605606
outlives
606607
}

src/librustc/infer/opaque_types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> {
803803
);
804804
debug!("instantiate_opaque_types: ty_var={:?}", ty_var);
805805

806+
self.obligations.reserve(bounds.predicates.len());
806807
for predicate in bounds.predicates {
807808
// Change the predicate to refer to the type variable,
808809
// which will be the concrete type instead of the opaque type.

0 commit comments

Comments
 (0)