From 4c33a5ac2f93ca2e4d0fb53bd8ecbcdffb8b23e2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 19 Nov 2019 17:55:59 +1100 Subject: [PATCH] Use a `SmallVec` for `Candidate::match_pairs`. This is a small win for `encoding`. --- src/librustc_mir/build/matches/mod.rs | 7 ++++--- src/librustc_mir/build/matches/util.rs | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 667b37bbd80c8..d33ddd1ecae33 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -17,6 +17,7 @@ use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty}; use rustc::ty::layout::VariantIdx; use rustc_index::bit_set::BitSet; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use smallvec::{SmallVec, smallvec}; use syntax::ast::Name; use syntax_pos::Span; @@ -166,7 +167,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |(pattern, pre_binding_block)| { Candidate { span: pattern.span, - match_pairs: vec![ + match_pairs: smallvec![ MatchPair::new(scrutinee_place.clone(), pattern), ], bindings: vec![], @@ -421,7 +422,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // create a dummy candidate let mut candidate = Candidate { span: irrefutable_pat.span, - match_pairs: vec![MatchPair::new(initializer.clone(), &irrefutable_pat)], + match_pairs: smallvec![MatchPair::new(initializer.clone(), &irrefutable_pat)], bindings: vec![], ascriptions: vec![], @@ -671,7 +672,7 @@ pub struct Candidate<'pat, 'tcx> { span: Span, // all of these must be satisfied... - match_pairs: Vec>, + match_pairs: SmallVec<[MatchPair<'pat, 'tcx>; 1]>, // ...these bindings established... bindings: Vec>, diff --git a/src/librustc_mir/build/matches/util.rs b/src/librustc_mir/build/matches/util.rs index 917535f31dc4b..aec9e6e57d46c 100644 --- a/src/librustc_mir/build/matches/util.rs +++ b/src/librustc_mir/build/matches/util.rs @@ -2,6 +2,7 @@ use crate::build::Builder; use crate::build::matches::MatchPair; use crate::hair::*; use rustc::mir::*; +use smallvec::SmallVec; use std::u32; use std::convert::TryInto; @@ -25,7 +26,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } pub fn prefix_slice_suffix<'pat>(&mut self, - match_pairs: &mut Vec>, + match_pairs: &mut SmallVec<[MatchPair<'pat, 'tcx>; 1]>, place: &Place<'tcx>, prefix: &'pat [Pat<'tcx>], opt_slice: Option<&'pat Pat<'tcx>>,