Skip to content

Commit 7e9fe1f

Browse files
committed
[perf] HIR analysis: Preallocate when lowering bounds
1 parent 84bdc5d commit 7e9fe1f

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn associated_type_bounds<'tcx>(
3737
);
3838

3939
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
40-
let mut bounds = Vec::new();
40+
let mut bounds = Vec::with_capacity(hir_bounds.len());
4141
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
4242
// Associated types are implicitly sized unless a `?Sized` bound is found
4343
match filter {
@@ -326,7 +326,7 @@ fn opaque_type_bounds<'tcx>(
326326
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
327327
ty::print::with_reduced_queries!({
328328
let icx = ItemCtxt::new(tcx, opaque_def_id);
329-
let mut bounds = Vec::new();
329+
let mut bounds = Vec::with_capacity(hir_bounds.len());
330330
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
331331
// Opaque types are implicitly sized unless a `?Sized` bound is found
332332
match filter {

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
177177
// on a trait we must also consider the bounds that follow the trait's name,
178178
// like `trait Foo: A + B + C`.
179179
if let Some(self_bounds) = is_trait {
180-
let mut bounds = Vec::new();
180+
let mut bounds = Vec::with_capacity(self_bounds.len());
181181
icx.lowerer().lower_bounds(
182182
tcx.types.self_param,
183183
self_bounds,
@@ -263,7 +263,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
263263
}
264264
}
265265

266-
let mut bounds = Vec::new();
266+
let mut bounds = Vec::with_capacity(bound_pred.bounds.len());
267267
icx.lowerer().lower_bounds(
268268
ty,
269269
bound_pred.bounds,
@@ -626,7 +626,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
626626
let icx = ItemCtxt::new(tcx, trait_def_id);
627627

628628
let self_param_ty = tcx.types.self_param;
629-
let mut bounds = Vec::new();
629+
let mut bounds = Vec::with_capacity(superbounds.len());
630630
icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter);
631631

632632
let where_bounds_that_match =

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2399,7 +2399,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23992399
// Impl trait in bindings lower as an infer var with additional
24002400
// set of type bounds.
24012401
let self_ty = self.ty_infer(None, hir_ty.span);
2402-
let mut bounds = Vec::new();
2402+
let mut bounds = Vec::with_capacity(hir_bounds.len());
24032403
self.lower_bounds(
24042404
self_ty,
24052405
hir_bounds.iter(),

0 commit comments

Comments
 (0)