Skip to content

Commit 388ffd9

Browse files
committed
Auto merge of #66540 - nnethercote:SmallVec-Candidate-match_pairs, r=matthewjasper
Use a `SmallVec` for `Candidate::match_pairs`. This is a small win for `encoding`. r? @matthewjasper
2 parents 412f43a + 4c33a5a commit 388ffd9

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/librustc_mir/build/matches/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty};
1717
use rustc::ty::layout::VariantIdx;
1818
use rustc_index::bit_set::BitSet;
1919
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
20+
use smallvec::{SmallVec, smallvec};
2021
use syntax::ast::Name;
2122
use syntax_pos::Span;
2223

@@ -166,7 +167,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
166167
|(pattern, pre_binding_block)| {
167168
Candidate {
168169
span: pattern.span,
169-
match_pairs: vec![
170+
match_pairs: smallvec![
170171
MatchPair::new(scrutinee_place.clone(), pattern),
171172
],
172173
bindings: vec![],
@@ -421,7 +422,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
421422
// create a dummy candidate
422423
let mut candidate = Candidate {
423424
span: irrefutable_pat.span,
424-
match_pairs: vec![MatchPair::new(initializer.clone(), &irrefutable_pat)],
425+
match_pairs: smallvec![MatchPair::new(initializer.clone(), &irrefutable_pat)],
425426
bindings: vec![],
426427
ascriptions: vec![],
427428

@@ -671,7 +672,7 @@ pub struct Candidate<'pat, 'tcx> {
671672
span: Span,
672673

673674
// all of these must be satisfied...
674-
match_pairs: Vec<MatchPair<'pat, 'tcx>>,
675+
match_pairs: SmallVec<[MatchPair<'pat, 'tcx>; 1]>,
675676

676677
// ...these bindings established...
677678
bindings: Vec<Binding<'tcx>>,

src/librustc_mir/build/matches/util.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::build::Builder;
22
use crate::build::matches::MatchPair;
33
use crate::hair::*;
44
use rustc::mir::*;
5+
use smallvec::SmallVec;
56
use std::u32;
67
use std::convert::TryInto;
78

@@ -25,7 +26,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2526
}
2627

2728
pub fn prefix_slice_suffix<'pat>(&mut self,
28-
match_pairs: &mut Vec<MatchPair<'pat, 'tcx>>,
29+
match_pairs: &mut SmallVec<[MatchPair<'pat, 'tcx>; 1]>,
2930
place: &Place<'tcx>,
3031
prefix: &'pat [Pat<'tcx>],
3132
opt_slice: Option<&'pat Pat<'tcx>>,

0 commit comments

Comments
 (0)