Use ThinVec in ast::PatKind::Struct.

This commit is contained in:
Nicholas Nethercote 2023-01-30 14:58:23 +11:00
parent 1807027248
commit 912b825002
5 changed files with 61 additions and 61 deletions

View File

@ -722,7 +722,7 @@ pub enum PatKind {
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
/// The `bool` is `true` in the presence of a `..`.
Struct(Option<P<QSelf>>, Path, Vec<PatField>, /* recovered */ bool),
Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, /* recovered */ bool),
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>),
@ -3128,10 +3128,10 @@ mod size_asserts {
static_assert_size!(Local, 72);
static_assert_size!(MetaItemLit, 40);
static_assert_size!(Param, 40);
static_assert_size!(Pat, 88);
static_assert_size!(Pat, 72);
static_assert_size!(Path, 24);
static_assert_size!(PathSegment, 24);
static_assert_size!(PatKind, 64);
static_assert_size!(PatKind, 48);
static_assert_size!(Stmt, 32);
static_assert_size!(StmtKind, 16);
static_assert_size!(Ty, 64);

View File

@ -224,11 +224,11 @@ fn show_fieldless_enum(
let pat = match &v.data {
ast::VariantData::Tuple(fields, _) => {
debug_assert!(fields.is_empty());
cx.pat_tuple_struct(span, variant_path, thin_vec![])
cx.pat_tuple_struct(span, variant_path, ThinVec::new())
}
ast::VariantData::Struct(fields, _) => {
debug_assert!(fields.is_empty());
cx.pat_struct(span, variant_path, vec![])
cx.pat_struct(span, variant_path, ThinVec::new())
}
ast::VariantData::Unit(_) => cx.pat_path(span, variant_path),
};

View File

@ -486,7 +486,7 @@ impl<'a> ExtCtxt<'a> {
&self,
span: Span,
path: ast::Path,
field_pats: Vec<ast::PatField>,
field_pats: ThinVec<ast::PatField>,
) -> P<ast::Pat> {
self.pat(span, PatKind::Struct(None, path, field_pats, false))
}

View File

@ -23,7 +23,7 @@ use rustc_errors::{
use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::source_map::{respan, Span, Spanned};
use rustc_span::symbol::{kw, sym, Ident};
use thin_vec::thin_vec;
use thin_vec::{thin_vec, ThinVec};
#[derive(PartialEq, Copy, Clone)]
pub enum Expected {
@ -854,7 +854,7 @@ impl<'a> Parser<'a> {
e.span_label(path.span, "while parsing the fields for this pattern");
e.emit();
self.recover_stmt();
(vec![], true)
(ThinVec::new(), true)
});
self.bump();
Ok(PatKind::Struct(qself, path, fields, etc))
@ -933,8 +933,8 @@ impl<'a> Parser<'a> {
}
/// Parses the fields of a struct-like pattern.
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<PatField>, bool)> {
let mut fields = Vec::new();
fn parse_pat_fields(&mut self) -> PResult<'a, (ThinVec<PatField>, bool)> {
let mut fields = ThinVec::new();
let mut etc = false;
let mut ate_comma = true;
let mut delayed_err: Option<DiagnosticBuilder<'a, ErrorGuaranteed>> = None;

View File

@ -7,7 +7,7 @@ ast-stats-1 ExprField 48 ( 0.7%) 1 48
ast-stats-1 WherePredicate 56 ( 0.8%) 1 56
ast-stats-1 - BoundPredicate 56 ( 0.8%) 1
ast-stats-1 Crate 56 ( 0.8%) 1 56
ast-stats-1 Attribute 64 ( 0.9%) 2 32
ast-stats-1 Attribute 64 ( 1.0%) 2 32
ast-stats-1 - Normal 32 ( 0.5%) 1
ast-stats-1 - DocComment 32 ( 0.5%) 1
ast-stats-1 Local 72 ( 1.1%) 1 72
@ -21,45 +21,45 @@ ast-stats-1 - Local 32 ( 0.5%) 1
ast-stats-1 - MacCall 32 ( 0.5%) 1
ast-stats-1 - Expr 96 ( 1.4%) 3
ast-stats-1 Param 160 ( 2.4%) 4 40
ast-stats-1 Block 192 ( 2.8%) 6 32
ast-stats-1 Block 192 ( 2.9%) 6 32
ast-stats-1 Variant 208 ( 3.1%) 2 104
ast-stats-1 GenericBound 224 ( 3.3%) 4 56
ast-stats-1 - Trait 224 ( 3.3%) 4
ast-stats-1 AssocItem 416 ( 6.2%) 4 104
ast-stats-1 GenericBound 224 ( 3.4%) 4 56
ast-stats-1 - Trait 224 ( 3.4%) 4
ast-stats-1 AssocItem 416 ( 6.3%) 4 104
ast-stats-1 - Type 208 ( 3.1%) 2
ast-stats-1 - Fn 208 ( 3.1%) 2
ast-stats-1 GenericParam 480 ( 7.1%) 5 96
ast-stats-1 Expr 576 ( 8.5%) 8 72
ast-stats-1 GenericParam 480 ( 7.2%) 5 96
ast-stats-1 Pat 504 ( 7.6%) 7 72
ast-stats-1 - Struct 72 ( 1.1%) 1
ast-stats-1 - Wild 72 ( 1.1%) 1
ast-stats-1 - Ident 360 ( 5.4%) 5
ast-stats-1 Expr 576 ( 8.7%) 8 72
ast-stats-1 - Path 72 ( 1.1%) 1
ast-stats-1 - Match 72 ( 1.1%) 1
ast-stats-1 - Struct 72 ( 1.1%) 1
ast-stats-1 - Lit 144 ( 2.1%) 2
ast-stats-1 - Block 216 ( 3.2%) 3
ast-stats-1 Pat 616 ( 9.1%) 7 88
ast-stats-1 - Struct 88 ( 1.3%) 1
ast-stats-1 - Wild 88 ( 1.3%) 1
ast-stats-1 - Ident 440 ( 6.5%) 5
ast-stats-1 PathSegment 720 (10.7%) 30 24
ast-stats-1 Ty 896 (13.3%) 14 64
ast-stats-1 - Ptr 64 ( 0.9%) 1
ast-stats-1 - Ref 64 ( 0.9%) 1
ast-stats-1 - Lit 144 ( 2.2%) 2
ast-stats-1 - Block 216 ( 3.3%) 3
ast-stats-1 PathSegment 720 (10.8%) 30 24
ast-stats-1 Ty 896 (13.5%) 14 64
ast-stats-1 - Ptr 64 ( 1.0%) 1
ast-stats-1 - Ref 64 ( 1.0%) 1
ast-stats-1 - ImplicitSelf 128 ( 1.9%) 2
ast-stats-1 - Path 640 ( 9.5%) 10
ast-stats-1 Item 1_296 (19.2%) 9 144
ast-stats-1 - Trait 144 ( 2.1%) 1
ast-stats-1 - Enum 144 ( 2.1%) 1
ast-stats-1 - ForeignMod 144 ( 2.1%) 1
ast-stats-1 - Impl 144 ( 2.1%) 1
ast-stats-1 - Path 640 ( 9.6%) 10
ast-stats-1 Item 1_296 (19.5%) 9 144
ast-stats-1 - Trait 144 ( 2.2%) 1
ast-stats-1 - Enum 144 ( 2.2%) 1
ast-stats-1 - ForeignMod 144 ( 2.2%) 1
ast-stats-1 - Impl 144 ( 2.2%) 1
ast-stats-1 - Fn 288 ( 4.3%) 2
ast-stats-1 - Use 432 ( 6.4%) 3
ast-stats-1 - Use 432 ( 6.5%) 3
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 Total 6_752
ast-stats-1 Total 6_640
ast-stats-1
ast-stats-2 POST EXPANSION AST STATS
ast-stats-2 Name Accumulated Size Count Item Size
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 GenericArgs 40 ( 0.5%) 1 40
ast-stats-2 - AngleBracketed 40 ( 0.5%) 1
ast-stats-2 GenericArgs 40 ( 0.6%) 1 40
ast-stats-2 - AngleBracketed 40 ( 0.6%) 1
ast-stats-2 ExprField 48 ( 0.7%) 1 48
ast-stats-2 WherePredicate 56 ( 0.8%) 1 56
ast-stats-2 - BoundPredicate 56 ( 0.8%) 1
@ -68,9 +68,9 @@ ast-stats-2 Local 72 ( 1.0%) 1 72
ast-stats-2 Arm 96 ( 1.3%) 2 48
ast-stats-2 ForeignItem 96 ( 1.3%) 1 96
ast-stats-2 - Fn 96 ( 1.3%) 1
ast-stats-2 InlineAsm 120 ( 1.6%) 1 120
ast-stats-2 FnDecl 120 ( 1.6%) 5 24
ast-stats-2 Attribute 128 ( 1.7%) 4 32
ast-stats-2 InlineAsm 120 ( 1.7%) 1 120
ast-stats-2 FnDecl 120 ( 1.7%) 5 24
ast-stats-2 Attribute 128 ( 1.8%) 4 32
ast-stats-2 - DocComment 32 ( 0.4%) 1
ast-stats-2 - Normal 96 ( 1.3%) 3
ast-stats-2 FieldDef 160 ( 2.2%) 2 80
@ -80,40 +80,40 @@ ast-stats-2 - Semi 32 ( 0.4%) 1
ast-stats-2 - Expr 96 ( 1.3%) 3
ast-stats-2 Param 160 ( 2.2%) 4 40
ast-stats-2 Block 192 ( 2.6%) 6 32
ast-stats-2 Variant 208 ( 2.8%) 2 104
ast-stats-2 GenericBound 224 ( 3.0%) 4 56
ast-stats-2 - Trait 224 ( 3.0%) 4
ast-stats-2 AssocItem 416 ( 5.6%) 4 104
ast-stats-2 - Type 208 ( 2.8%) 2
ast-stats-2 - Fn 208 ( 2.8%) 2
ast-stats-2 GenericParam 480 ( 6.5%) 5 96
ast-stats-2 Pat 616 ( 8.4%) 7 88
ast-stats-2 - Struct 88 ( 1.2%) 1
ast-stats-2 - Wild 88 ( 1.2%) 1
ast-stats-2 - Ident 440 ( 6.0%) 5
ast-stats-2 Expr 648 ( 8.8%) 9 72
ast-stats-2 Variant 208 ( 2.9%) 2 104
ast-stats-2 GenericBound 224 ( 3.1%) 4 56
ast-stats-2 - Trait 224 ( 3.1%) 4
ast-stats-2 AssocItem 416 ( 5.7%) 4 104
ast-stats-2 - Type 208 ( 2.9%) 2
ast-stats-2 - Fn 208 ( 2.9%) 2
ast-stats-2 GenericParam 480 ( 6.6%) 5 96
ast-stats-2 Pat 504 ( 6.9%) 7 72
ast-stats-2 - Struct 72 ( 1.0%) 1
ast-stats-2 - Wild 72 ( 1.0%) 1
ast-stats-2 - Ident 360 ( 5.0%) 5
ast-stats-2 Expr 648 ( 8.9%) 9 72
ast-stats-2 - Path 72 ( 1.0%) 1
ast-stats-2 - Match 72 ( 1.0%) 1
ast-stats-2 - Struct 72 ( 1.0%) 1
ast-stats-2 - InlineAsm 72 ( 1.0%) 1
ast-stats-2 - Lit 144 ( 2.0%) 2
ast-stats-2 - Block 216 ( 2.9%) 3
ast-stats-2 PathSegment 792 (10.7%) 33 24
ast-stats-2 Ty 896 (12.2%) 14 64
ast-stats-2 - Block 216 ( 3.0%) 3
ast-stats-2 PathSegment 792 (10.9%) 33 24
ast-stats-2 Ty 896 (12.3%) 14 64
ast-stats-2 - Ptr 64 ( 0.9%) 1
ast-stats-2 - Ref 64 ( 0.9%) 1
ast-stats-2 - ImplicitSelf 128 ( 1.7%) 2
ast-stats-2 - Path 640 ( 8.7%) 10
ast-stats-2 Item 1_584 (21.5%) 11 144
ast-stats-2 - ImplicitSelf 128 ( 1.8%) 2
ast-stats-2 - Path 640 ( 8.8%) 10
ast-stats-2 Item 1_584 (21.8%) 11 144
ast-stats-2 - Trait 144 ( 2.0%) 1
ast-stats-2 - Enum 144 ( 2.0%) 1
ast-stats-2 - ExternCrate 144 ( 2.0%) 1
ast-stats-2 - ForeignMod 144 ( 2.0%) 1
ast-stats-2 - Impl 144 ( 2.0%) 1
ast-stats-2 - Fn 288 ( 3.9%) 2
ast-stats-2 - Use 576 ( 7.8%) 4
ast-stats-2 - Fn 288 ( 4.0%) 2
ast-stats-2 - Use 576 ( 7.9%) 4
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 Total 7_368
ast-stats-2 Total 7_256
ast-stats-2
hir-stats HIR STATS
hir-stats Name Accumulated Size Count Item Size