Skip to content

Commit 0c4d337

Browse files
authored
Rollup merge of #50963 - nnethercote:coercion-VecDeque1, r=petrochenkov
Right-size the `VecDeque` in `coerce_unsized`. The default capacity of a VecDeque is 8, which is excessive here. In a "base incremental" check build of rustc-perf's tuple-stress benchmark, this decreases total heap allocation by 26%. I couldn't see a clear speedup, but it can't hurt.
2 parents 28e4358 + a86544b commit 0c4d337

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/librustc_typeck/check/coercion.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
537537

538538
let mut selcx = traits::SelectionContext::new(self);
539539

540-
// Use a FIFO queue for this custom fulfillment procedure.
541-
let mut queue = VecDeque::new();
540+
// Use a FIFO queue for this custom fulfillment procedure. (The maximum
541+
// length is almost always 1.)
542+
let mut queue = VecDeque::with_capacity(1);
542543

543544
// Create an obligation for `Source: CoerceUnsized<Target>`.
544545
let cause = ObligationCause::misc(self.cause.span, self.body_id);

0 commit comments

Comments
 (0)