From b3f5af205d6d034e4491d5888d928717b8fca82a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 25 Jul 2024 11:14:55 +0200 Subject: [PATCH] Reduce size of TypeRef by 8 bytes --- .../crates/hir-def/src/hir/type_ref.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs b/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs index 9b0543225881..4cca42ed1ab4 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs @@ -121,7 +121,7 @@ pub enum TypeRef { Slice(Box), /// A fn pointer. Last element of the vector is the return type. Fn( - Vec<(Option, TypeRef)>, + Box<[(Option, TypeRef)]>, bool, /*varargs*/ bool, /*is_unsafe*/ Option, /* abi */ @@ -228,7 +228,7 @@ impl TypeRef { }) .collect() } else { - Vec::new() + Vec::with_capacity(1) }; fn lower_abi(abi: ast::Abi) -> Symbol { match abi.abi_string() { @@ -240,7 +240,7 @@ impl TypeRef { let abi = inner.abi().map(lower_abi); params.push((None, ret_ty)); - TypeRef::Fn(params, is_varargs, inner.unsafe_token().is_some(), abi) + TypeRef::Fn(params.into(), is_varargs, inner.unsafe_token().is_some(), abi) } // for types are close enough for our purposes to the inner type for now... ast::Type::ForType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()), @@ -396,7 +396,7 @@ impl TypeBound { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum ConstRef { - Scalar(LiteralConstRef), + Scalar(Box), Path(Name), Complex(AstId), } @@ -408,7 +408,7 @@ impl ConstRef { return Self::from_expr(expr, Some(lower_ctx.ast_id(&arg))); } } - Self::Scalar(LiteralConstRef::Unknown) + Self::Scalar(Box::new(LiteralConstRef::Unknown)) } pub(crate) fn from_const_param( @@ -452,10 +452,10 @@ impl ConstRef { ast::Expr::PathExpr(p) if is_path_ident(&p) => { match p.path().and_then(|it| it.segment()).and_then(|it| it.name_ref()) { Some(it) => Self::Path(it.as_name()), - None => Self::Scalar(LiteralConstRef::Unknown), + None => Self::Scalar(Box::new(LiteralConstRef::Unknown)), } } - ast::Expr::Literal(literal) => Self::Scalar(match literal.kind() { + ast::Expr::Literal(literal) => Self::Scalar(Box::new(match literal.kind() { ast::LiteralKind::IntNumber(num) => { num.value().map(LiteralConstRef::UInt).unwrap_or(LiteralConstRef::Unknown) } @@ -464,12 +464,12 @@ impl ConstRef { } ast::LiteralKind::Bool(f) => LiteralConstRef::Bool(f), _ => LiteralConstRef::Unknown, - }), + })), _ => { if let Some(ast_id) = ast_id { Self::Complex(ast_id) } else { - Self::Scalar(LiteralConstRef::Unknown) + Self::Scalar(Box::new(LiteralConstRef::Unknown)) } } }