diff options
| author | Martin Gammelsæter <martin@mg.am> | 2022-04-13 17:46:29 +0200 |
|---|---|---|
| committer | Martin Gammelsæter <martin@mg.am> | 2022-04-16 17:42:27 +0200 |
| commit | 041121a18434023982b88b0d60f92ee904df4f49 (patch) | |
| tree | ac1d8983f09440129c2c56e68519ea7868a9c7ed | |
| parent | 4e1927db3c399fa34dc71992bd5dbec09f945c3d (diff) | |
| download | rust-041121a18434023982b88b0d60f92ee904df4f49.tar.gz rust-041121a18434023982b88b0d60f92ee904df4f49.zip | |
Optimize relate_substs by extracting match
There was no need to keep doing the match inside the iterator.
| -rw-r--r-- | compiler/rustc_middle/src/ty/relate.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index d9b55563996..b1cfa3fa964 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -142,11 +142,12 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>( b_subst: SubstsRef<'tcx>, ) -> RelateResult<'tcx, SubstsRef<'tcx>> { let tcx = relation.tcx(); - let mut cached_ty = None; - let params = iter::zip(a_subst, b_subst).enumerate().map(|(i, (a, b))| { - let (variance, variance_info) = match variances { - Some((ty_def_id, variances)) => { + let zipped = iter::zip(a_subst, b_subst); + match 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_info = if variance == ty::Invariant { let ty = *cached_ty @@ -155,14 +156,13 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>( } else { ty::VarianceDiagInfo::default() }; - (variance, variance_info) - } - None => (ty::Invariant, ty::VarianceDiagInfo::default()), - }; - relation.relate_with_variance(variance, variance_info, a, b) - }); - - tcx.mk_substs(params) + relation.relate_with_variance(variance, variance_info, a, b) + })) + } + 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> { |
