Unnamed repository; edit this file 'description' to name the repository.
internal: Shrink hir::Expr from 64 to 48 bytes
Lukas Wirth 3 weeks ago
parent 3dc8278 · commit 49c2f93
-rw-r--r--crates/hir-def/src/expr_store/lower.rs4
-rw-r--r--crates/hir-def/src/expr_store/lower/format_args.rs7
-rw-r--r--crates/hir-def/src/hir.rs6
3 files changed, 13 insertions, 4 deletions
diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs
index 0320f6b93b..fd5b25ca2f 100644
--- a/crates/hir-def/src/expr_store/lower.rs
+++ b/crates/hir-def/src/expr_store/lower.rs
@@ -1310,10 +1310,10 @@ impl<'db> ExprCollector<'db> {
/// Returns `None` if and only if the expression is `#[cfg]`d out.
fn maybe_collect_expr(&mut self, expr: ast::Expr) -> Option<ExprId> {
- let syntax_ptr = AstPtr::new(&expr);
if !self.check_cfg(&expr) {
return None;
}
+ let syntax_ptr = AstPtr::new(&expr);
// FIXME: Move some of these arms out into separate methods for clarity
Some(match expr {
@@ -1589,7 +1589,7 @@ impl<'db> ExprCollector<'db> {
};
Expr::RecordLit { path, fields, spread }
} else {
- Expr::RecordLit { path, fields: Box::default(), spread: RecordSpread::None }
+ Expr::RecordLit { path, fields: ThinVec::default(), spread: RecordSpread::None }
};
self.alloc_expr(record_lit, syntax_ptr)
diff --git a/crates/hir-def/src/expr_store/lower/format_args.rs b/crates/hir-def/src/expr_store/lower/format_args.rs
index b058ad6d9a..1ecd18fb53 100644
--- a/crates/hir-def/src/expr_store/lower/format_args.rs
+++ b/crates/hir-def/src/expr_store/lower/format_args.rs
@@ -5,6 +5,7 @@ use hir_expand::name::Name;
use intern::{Symbol, sym};
use span::SyntaxContext;
use syntax::{AstPtr, AstToken as _, ast};
+use thin_vec::ThinVec;
use crate::{
builtin_type::BuiltinUint,
@@ -875,7 +876,11 @@ impl<'db> ExprCollector<'db> {
match self.lang_path(lang_items.FormatPlaceholder) {
Some(path) => self.alloc_expr_desugared(Expr::RecordLit {
path,
- fields: Box::new([position, flags, precision, width]),
+ fields: {
+ let mut fields = ThinVec::with_capacity(4);
+ fields.extend([position, flags, precision, width]);
+ fields
+ },
spread: RecordSpread::None,
}),
None => self.missing_expr(),
diff --git a/crates/hir-def/src/hir.rs b/crates/hir-def/src/hir.rs
index a800569044..df30137372 100644
--- a/crates/hir-def/src/hir.rs
+++ b/crates/hir-def/src/hir.rs
@@ -23,6 +23,7 @@ use intern::Symbol;
use la_arena::Idx;
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use syntax::ast;
+use thin_vec::ThinVec;
use type_ref::TypeRefId;
use crate::{
@@ -261,7 +262,7 @@ pub enum Expr {
},
RecordLit {
path: Path,
- fields: Box<[RecordLitField]>,
+ fields: ThinVec<RecordLitField>,
spread: RecordSpread,
},
Field {
@@ -326,6 +327,9 @@ pub enum Expr {
IncludeBytes,
}
+#[cfg(target_pointer_width = "64")]
+const _: () = assert!(std::mem::size_of::<Expr>() == 48);
+
impl Expr {
pub fn precedence(&self) -> ast::prec::ExprPrecedence {
use ast::prec::ExprPrecedence;