From 32304d14a1a5e316615028ffd7bcfcff682fbe56 Mon Sep 17 00:00:00 2001 From: Alexandru Macovei Date: Wed, 31 Mar 2021 00:55:18 +0300 Subject: Use Box'es to reduce the size of hir_def::expr::Pat from 112 to 64 bytes on 64bit --- crates/hir_def/src/body/lower.rs | 6 +++--- crates/hir_def/src/expr.rs | 6 +++--- crates/hir_def/src/path.rs | 6 ++++++ 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'crates/hir_def') diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs index 73e7aee33..1e743e5d5 100644 --- a/crates/hir_def/src/body/lower.rs +++ b/crates/hir_def/src/body/lower.rs @@ -759,7 +759,7 @@ impl ExprCollector<'_> { } } ast::Pat::TupleStructPat(p) => { - let path = p.path().and_then(|path| self.expander.parse_path(path)); + let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); let (args, ellipsis) = self.collect_tuple_pat(p.fields()); Pat::TupleStruct { path, args, ellipsis } } @@ -769,7 +769,7 @@ impl ExprCollector<'_> { Pat::Ref { pat, mutability } } ast::Pat::PathPat(p) => { - let path = p.path().and_then(|path| self.expander.parse_path(path)); + let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); path.map(Pat::Path).unwrap_or(Pat::Missing) } ast::Pat::OrPat(p) => { @@ -783,7 +783,7 @@ impl ExprCollector<'_> { } ast::Pat::WildcardPat(_) => Pat::Wild, ast::Pat::RecordPat(p) => { - let path = p.path().and_then(|path| self.expander.parse_path(path)); + let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); let args: Vec<_> = p .record_pat_field_list() .expect("every struct should have a field list") diff --git a/crates/hir_def/src/expr.rs b/crates/hir_def/src/expr.rs index ba00b9609..62a28bdba 100644 --- a/crates/hir_def/src/expr.rs +++ b/crates/hir_def/src/expr.rs @@ -412,13 +412,13 @@ pub enum Pat { Wild, Tuple { args: Vec, ellipsis: Option }, Or(Vec), - Record { path: Option, args: Vec, ellipsis: bool }, + Record { path: Option>, args: Vec, ellipsis: bool }, Range { start: ExprId, end: ExprId }, Slice { prefix: Vec, slice: Option, suffix: Vec }, - Path(Path), + Path(Box), Lit(ExprId), Bind { mode: BindingAnnotation, name: Name, subpat: Option }, - TupleStruct { path: Option, args: Vec, ellipsis: Option }, + TupleStruct { path: Option>, args: Vec, ellipsis: Option }, Ref { pat: PatId, mutability: Mutability }, Box { inner: PatId }, ConstBlock(ExprId), diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index f9c8328f0..b528ff8ba 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs @@ -289,6 +289,12 @@ impl From for Path { } } +impl From for Box { + fn from(name: Name) -> Box { + Box::new(Path::from(name)) + } +} + impl From for ModPath { fn from(name: Name) -> ModPath { ModPath::from_segments(PathKind::Plain, iter::once(name)) -- cgit v1.2.3