Use ThinVec in ast::ExprKind::Match.

This commit is contained in:
Nicholas Nethercote 2023-01-30 15:10:59 +11:00
parent 912b825002
commit 549f1c60af
8 changed files with 9 additions and 9 deletions

View File

@ -1414,7 +1414,7 @@ pub enum ExprKind {
/// `'label: loop { block }`
Loop(P<Block>, Option<Label>, Span),
/// A `match` block.
Match(P<Expr>, Vec<Arm>),
Match(P<Expr>, ThinVec<Arm>),
/// A closure (e.g., `move |a, b, c| a + b + c`).
Closure(Box<Closure>),
/// A block (`'label: { ... }`).

View File

@ -71,7 +71,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> Bl
let eq_arm = cx.arm(span, cx.pat_path(span, equal_path.clone()), expr1);
let neq_arm =
cx.arm(span, cx.pat_ident(span, test_id), cx.expr_ident(span, test_id));
cx.expr_match(span, expr2, vec![eq_arm, neq_arm])
cx.expr_match(span, expr2, thin_vec![eq_arm, neq_arm])
}
CsFold::Fieldless => cx.expr_path(equal_path.clone()),
},

View File

@ -143,7 +143,7 @@ fn cs_partial_cmp(
cx.arm(span, cx.pat_some(span, cx.pat_path(span, equal_path.clone())), expr1);
let neq_arm =
cx.arm(span, cx.pat_ident(span, test_id), cx.expr_ident(span, test_id));
cx.expr_match(span, expr2, vec![eq_arm, neq_arm])
cx.expr_match(span, expr2, thin_vec![eq_arm, neq_arm])
}
}
CsFold::Fieldless => cx.expr_some(span, cx.expr_path(equal_path.clone())),

View File

@ -234,7 +234,7 @@ fn show_fieldless_enum(
};
cx.arm(span, pat, cx.expr_str(span, v.ident.name))
})
.collect::<Vec<_>>();
.collect::<ThinVec<_>>();
let name = cx.expr_match(span, cx.expr_self(span), arms);
let fn_path_write_str = cx.std_path(&[sym::fmt, sym::Formatter, sym::write_str]);
BlockOrExpr::new_expr(cx.expr_call_global(span, fn_path_write_str, thin_vec![fmt, name]))

View File

@ -123,7 +123,7 @@ fn decodable_substructure(
StaticEnum(_, fields) => {
let variant = Ident::new(sym::i, trait_span);
let mut arms = Vec::with_capacity(fields.len() + 1);
let mut arms = ThinVec::with_capacity(fields.len() + 1);
let mut variants = ThinVec::with_capacity(fields.len());
let fn_read_enum_variant_arg_path: Vec<_> =

View File

@ -1247,7 +1247,7 @@ impl<'a> MethodDef<'a> {
// (Variant2, Variant2, ...) => Body2
// ...
// where each tuple has length = selflike_args.len()
let mut match_arms: Vec<ast::Arm> = variants
let mut match_arms: ThinVec<ast::Arm> = variants
.iter()
.enumerate()
.filter(|&(_, v)| !(unify_fieldless_variants && v.data.fields().is_empty()))

View File

@ -446,7 +446,7 @@ impl<'a> ExtCtxt<'a> {
let err_arm = self.arm(sp, err_pat, err_expr);
// `match head { Ok() => ..., Err() => ... }`
self.expr_match(sp, head, vec![ok_arm, err_arm])
self.expr_match(sp, head, thin_vec![ok_arm, err_arm])
}
pub fn pat(&self, span: Span, kind: PatKind) -> P<ast::Pat> {
@ -516,7 +516,7 @@ impl<'a> ExtCtxt<'a> {
self.arm(span, self.pat_wild(span), self.expr_unreachable(span))
}
pub fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm>) -> P<Expr> {
pub fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: ThinVec<ast::Arm>) -> P<Expr> {
self.expr(span, ast::ExprKind::Match(arg, arms))
}

View File

@ -2566,7 +2566,7 @@ impl<'a> Parser<'a> {
}
let attrs = self.parse_inner_attributes()?;
let mut arms: Vec<Arm> = Vec::new();
let mut arms = ThinVec::new();
while self.token != token::CloseDelim(Delimiter::Brace) {
match self.parse_arm() {
Ok(arm) => arms.push(arm),