Skip to content

Commit

Permalink
Rollup merge of #50963 - nnethercote:coercion-VecDeque1, r=petrochenkov
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kennytm authored May 22, 2018
2 parents 28e4358 + a86544b commit 0c4d337
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/librustc_typeck/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,9 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {

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

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

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

0 comments on commit 0c4d337

Please sign in to comment.