aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src
diff options
context:
space:
mode:
authorAlexandru Macovei <[email protected]>2021-03-30 22:55:18 +0100
committerAlexandru Macovei <[email protected]>2021-04-06 14:01:31 +0100
commit32304d14a1a5e316615028ffd7bcfcff682fbe56 (patch)
tree4dda8757645c339a0ea6a926456ce7edf4ec4de7 /crates/hir_def/src
parentfb1f544e2479addd5957688e297ea04ddf0cf249 (diff)
Use Box'es to reduce the size of hir_def::expr::Pat from 112 to 64 bytes on 64bit
Diffstat (limited to 'crates/hir_def/src')
-rw-r--r--crates/hir_def/src/body/lower.rs6
-rw-r--r--crates/hir_def/src/expr.rs6
-rw-r--r--crates/hir_def/src/path.rs6
3 files changed, 12 insertions, 6 deletions
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<'_> {
759 } 759 }
760 } 760 }
761 ast::Pat::TupleStructPat(p) => { 761 ast::Pat::TupleStructPat(p) => {
762 let path = p.path().and_then(|path| self.expander.parse_path(path)); 762 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
763 let (args, ellipsis) = self.collect_tuple_pat(p.fields()); 763 let (args, ellipsis) = self.collect_tuple_pat(p.fields());
764 Pat::TupleStruct { path, args, ellipsis } 764 Pat::TupleStruct { path, args, ellipsis }
765 } 765 }
@@ -769,7 +769,7 @@ impl ExprCollector<'_> {
769 Pat::Ref { pat, mutability } 769 Pat::Ref { pat, mutability }
770 } 770 }
771 ast::Pat::PathPat(p) => { 771 ast::Pat::PathPat(p) => {
772 let path = p.path().and_then(|path| self.expander.parse_path(path)); 772 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
773 path.map(Pat::Path).unwrap_or(Pat::Missing) 773 path.map(Pat::Path).unwrap_or(Pat::Missing)
774 } 774 }
775 ast::Pat::OrPat(p) => { 775 ast::Pat::OrPat(p) => {
@@ -783,7 +783,7 @@ impl ExprCollector<'_> {
783 } 783 }
784 ast::Pat::WildcardPat(_) => Pat::Wild, 784 ast::Pat::WildcardPat(_) => Pat::Wild,
785 ast::Pat::RecordPat(p) => { 785 ast::Pat::RecordPat(p) => {
786 let path = p.path().and_then(|path| self.expander.parse_path(path)); 786 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new);
787 let args: Vec<_> = p 787 let args: Vec<_> = p
788 .record_pat_field_list() 788 .record_pat_field_list()
789 .expect("every struct should have a field list") 789 .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 {
412 Wild, 412 Wild,
413 Tuple { args: Vec<PatId>, ellipsis: Option<usize> }, 413 Tuple { args: Vec<PatId>, ellipsis: Option<usize> },
414 Or(Vec<PatId>), 414 Or(Vec<PatId>),
415 Record { path: Option<Path>, args: Vec<RecordFieldPat>, ellipsis: bool }, 415 Record { path: Option<Box<Path>>, args: Vec<RecordFieldPat>, ellipsis: bool },
416 Range { start: ExprId, end: ExprId }, 416 Range { start: ExprId, end: ExprId },
417 Slice { prefix: Vec<PatId>, slice: Option<PatId>, suffix: Vec<PatId> }, 417 Slice { prefix: Vec<PatId>, slice: Option<PatId>, suffix: Vec<PatId> },
418 Path(Path), 418 Path(Box<Path>),
419 Lit(ExprId), 419 Lit(ExprId),
420 Bind { mode: BindingAnnotation, name: Name, subpat: Option<PatId> }, 420 Bind { mode: BindingAnnotation, name: Name, subpat: Option<PatId> },
421 TupleStruct { path: Option<Path>, args: Vec<PatId>, ellipsis: Option<usize> }, 421 TupleStruct { path: Option<Box<Path>>, args: Vec<PatId>, ellipsis: Option<usize> },
422 Ref { pat: PatId, mutability: Mutability }, 422 Ref { pat: PatId, mutability: Mutability },
423 Box { inner: PatId }, 423 Box { inner: PatId },
424 ConstBlock(ExprId), 424 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<Name> for Path {
289 } 289 }
290} 290}
291 291
292impl From<Name> for Box<Path> {
293 fn from(name: Name) -> Box<Path> {
294 Box::new(Path::from(name))
295 }
296}
297
292impl From<Name> for ModPath { 298impl From<Name> for ModPath {
293 fn from(name: Name) -> ModPath { 299 fn from(name: Name) -> ModPath {
294 ModPath::from_segments(PathKind::Plain, iter::once(name)) 300 ModPath::from_segments(PathKind::Plain, iter::once(name))