Skip to content

Commit d1a7bb3

Browse files
committed
Avoid SmallVec::collect() in List<Predicate>::super_fold_with().
Also avoid interning when it's not necessary. This commit reduces instruction counts for a couple of benchmarks by up to 1%.
1 parent 1937c20 commit d1a7bb3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/librustc/ty/structural_impls.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1223,8 +1223,21 @@ BraceStructTypeFoldableImpl! {
12231223

12241224
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<ty::Predicate<'tcx>> {
12251225
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
1226-
let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
1227-
folder.tcx().intern_predicates(&v)
1226+
// This code is hot enough that it's worth specializing for a list of
1227+
// length 0. (No other length is common enough to be worth singling
1228+
// out).
1229+
if self.len() == 0 {
1230+
self
1231+
} else {
1232+
// Don't bother interning if nothing changed, which is the common
1233+
// case.
1234+
let v = self.iter().map(|p| p.fold_with(folder)).collect::<SmallVec<[_; 8]>>();
1235+
if v[..] == self[..] {
1236+
self
1237+
} else {
1238+
folder.tcx().intern_predicates(&v)
1239+
}
1240+
}
12281241
}
12291242

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

0 commit comments

Comments
 (0)