From 4d0618ee3014b96287bb6914296b78bd474b0290 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 24 Nov 2016 21:10:08 +1100 Subject: [PATCH] Avoid more unnecessary mk_ty calls in Ty::super_fold_with. This speeds up several rustc-benchmarks by 1--5%. --- src/librustc/ty/structural_impls.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index e73be23a42c..877da7ee3b5 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -481,7 +481,12 @@ impl<'tcx> TypeFoldable<'tcx> for Ty<'tcx> { ty::TyUint(_) | ty::TyFloat(_) | ty::TyError | ty::TyInfer(_) | ty::TyParam(..) | ty::TyNever => return self }; - folder.tcx().mk_ty(sty) + + if self.sty == sty { + self + } else { + folder.tcx().mk_ty(sty) + } } fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {