Skip to content

Commit

Permalink
Avoid SmallVec::collect() in List<Predicate>::super_fold_with().
Browse files Browse the repository at this point in the history
Also avoid interning when it's not necessary.

This commit reduces instruction counts for a couple of benchmarks by up to 1%.
  • Loading branch information
nnethercote committed Oct 1, 2019
1 parent 1937c20 commit d1a7bb3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/librustc/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,8 +1223,21 @@ BraceStructTypeFoldableImpl! {

impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
folder.tcx().intern_predicates(&v)
// This code is hot enough that it's worth specializing for a list of
// length 0. (No other length is common enough to be worth singling
// out).
if self.len() == 0 {
self
} else {
// Don't bother interning if nothing changed, which is the common
// case.
let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
if v[..] == self[..] {
self
} else {
folder.tcx().intern_predicates(&v)
}
}
}

fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
Expand Down

0 comments on commit d1a7bb3

Please sign in to comment.