Optimize relate_substs by extracting match
There was no need to keep doing the match inside the iterator.
This commit is contained in:
parent
4e1927db3c
commit
041121a184
1 changed files with 12 additions and 12 deletions
|
@ -142,11 +142,12 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>(
|
||||||
b_subst: SubstsRef<'tcx>,
|
b_subst: SubstsRef<'tcx>,
|
||||||
) -> RelateResult<'tcx, SubstsRef<'tcx>> {
|
) -> RelateResult<'tcx, SubstsRef<'tcx>> {
|
||||||
let tcx = relation.tcx();
|
let tcx = relation.tcx();
|
||||||
let mut cached_ty = None;
|
|
||||||
|
|
||||||
let params = iter::zip(a_subst, b_subst).enumerate().map(|(i, (a, b))| {
|
let zipped = iter::zip(a_subst, b_subst);
|
||||||
let (variance, variance_info) = match variances {
|
match variances {
|
||||||
Some((ty_def_id, variances)) => {
|
Some((ty_def_id, variances)) => {
|
||||||
|
let mut cached_ty = None;
|
||||||
|
tcx.mk_substs(zipped.enumerate().map(|(i, (a, b))| {
|
||||||
let variance = variances[i];
|
let variance = variances[i];
|
||||||
let variance_info = if variance == ty::Invariant {
|
let variance_info = if variance == ty::Invariant {
|
||||||
let ty = *cached_ty
|
let ty = *cached_ty
|
||||||
|
@ -155,14 +156,13 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>(
|
||||||
} else {
|
} else {
|
||||||
ty::VarianceDiagInfo::default()
|
ty::VarianceDiagInfo::default()
|
||||||
};
|
};
|
||||||
(variance, variance_info)
|
|
||||||
}
|
|
||||||
None => (ty::Invariant, ty::VarianceDiagInfo::default()),
|
|
||||||
};
|
|
||||||
relation.relate_with_variance(variance, variance_info, a, b)
|
relation.relate_with_variance(variance, variance_info, a, b)
|
||||||
});
|
}))
|
||||||
|
}
|
||||||
tcx.mk_substs(params)
|
None => tcx.mk_substs(zipped.map(|(a, b)| {
|
||||||
|
relation.relate_with_variance(ty::Invariant, ty::VarianceDiagInfo::default(), a, b)
|
||||||
|
})),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
|
impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue