Skip to content

Commit 8b5bc95

Browse files
committed
Only calculate trait_ref.self_ty() once in get_blanket_impls
On crates with many blanket impls, such as `stm32`, this inner closure is executed many hundreds of thousands of times. This makes it very slightly faster. Unfortunately, I don't have a good test case for showing that it's faster until rust-lang/rustc-perf#802 is merged.
1 parent edeee91 commit 8b5bc95

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/librustdoc/clean/blanket_impl.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
3232
trait_def_id, impl_def_id
3333
);
3434
let trait_ref = self.cx.tcx.impl_trait_ref(impl_def_id).unwrap();
35+
let trait_ty = trait_ref.self_ty();
3536
let may_apply = self.cx.tcx.infer_ctxt().enter(|infcx| {
36-
match trait_ref.self_ty().kind() {
37+
match trait_ty.kind() {
3738
ty::Param(_) => {}
3839
_ => return false,
3940
}
@@ -48,7 +49,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
4849
// Require the type the impl is implemented on to match
4950
// our type, and ignore the impl if there was a mismatch.
5051
let cause = traits::ObligationCause::dummy();
51-
let eq_result = infcx.at(&cause, param_env).eq(trait_ref.self_ty(), ty);
52+
let eq_result = infcx.at(&cause, param_env).eq(trait_ty, ty);
5253
if let Ok(InferOk { value: (), obligations }) = eq_result {
5354
// FIXME(eddyb) ignoring `obligations` might cause false positives.
5455
drop(obligations);
@@ -128,7 +129,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
128129
.clean(self.cx),
129130
negative_polarity: false,
130131
synthetic: false,
131-
blanket_impl: Some(trait_ref.self_ty().clean(self.cx)),
132+
blanket_impl: Some(trait_ty.clean(self.cx)),
132133
}),
133134
});
134135
});

0 commit comments

Comments
 (0)