Skip to content

Commit

Permalink
Optimize Substs::super_fold_with.
Browse files Browse the repository at this point in the history
This speeds up several rustc-benchmarks by 1--4%.
  • Loading branch information
nnethercote committed Oct 18, 2016
1 parent 1d3dfa5 commit 1e4241a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/librustc/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,15 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {

impl<'tcx> TypeFoldable<'tcx> for &'tcx Substs<'tcx> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
let params = self.iter().map(|k| k.fold_with(folder)).collect();
folder.tcx().mk_substs(params)
let params: Vec<_> = self.iter().map(|k| k.fold_with(folder)).collect();

// If folding doesn't change the substs, it's faster to avoid calling
// `mk_substs` and instead reuse the existing substs.
if params[..] == self[..] {
self
} else {
folder.tcx().mk_substs(params)
}
}

fn fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
Expand Down

0 comments on commit 1e4241a

Please sign in to comment.