Skip to content

Commit b3f5af2

Browse files
committed
Reduce size of TypeRef by 8 bytes
1 parent d744b7c commit b3f5af2

File tree

1 file changed

+9
-9
lines changed
  • src/tools/rust-analyzer/crates/hir-def/src/hir

1 file changed

+9
-9
lines changed

src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub enum TypeRef {
121121
Slice(Box<TypeRef>),
122122
/// A fn pointer. Last element of the vector is the return type.
123123
Fn(
124-
Vec<(Option<Name>, TypeRef)>,
124+
Box<[(Option<Name>, TypeRef)]>,
125125
bool, /*varargs*/
126126
bool, /*is_unsafe*/
127127
Option<Symbol>, /* abi */
@@ -228,7 +228,7 @@ impl TypeRef {
228228
})
229229
.collect()
230230
} else {
231-
Vec::new()
231+
Vec::with_capacity(1)
232232
};
233233
fn lower_abi(abi: ast::Abi) -> Symbol {
234234
match abi.abi_string() {
@@ -240,7 +240,7 @@ impl TypeRef {
240240

241241
let abi = inner.abi().map(lower_abi);
242242
params.push((None, ret_ty));
243-
TypeRef::Fn(params, is_varargs, inner.unsafe_token().is_some(), abi)
243+
TypeRef::Fn(params.into(), is_varargs, inner.unsafe_token().is_some(), abi)
244244
}
245245
// for types are close enough for our purposes to the inner type for now...
246246
ast::Type::ForType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()),
@@ -396,7 +396,7 @@ impl TypeBound {
396396

397397
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
398398
pub enum ConstRef {
399-
Scalar(LiteralConstRef),
399+
Scalar(Box<LiteralConstRef>),
400400
Path(Name),
401401
Complex(AstId<ast::ConstArg>),
402402
}
@@ -408,7 +408,7 @@ impl ConstRef {
408408
return Self::from_expr(expr, Some(lower_ctx.ast_id(&arg)));
409409
}
410410
}
411-
Self::Scalar(LiteralConstRef::Unknown)
411+
Self::Scalar(Box::new(LiteralConstRef::Unknown))
412412
}
413413

414414
pub(crate) fn from_const_param(
@@ -452,10 +452,10 @@ impl ConstRef {
452452
ast::Expr::PathExpr(p) if is_path_ident(&p) => {
453453
match p.path().and_then(|it| it.segment()).and_then(|it| it.name_ref()) {
454454
Some(it) => Self::Path(it.as_name()),
455-
None => Self::Scalar(LiteralConstRef::Unknown),
455+
None => Self::Scalar(Box::new(LiteralConstRef::Unknown)),
456456
}
457457
}
458-
ast::Expr::Literal(literal) => Self::Scalar(match literal.kind() {
458+
ast::Expr::Literal(literal) => Self::Scalar(Box::new(match literal.kind() {
459459
ast::LiteralKind::IntNumber(num) => {
460460
num.value().map(LiteralConstRef::UInt).unwrap_or(LiteralConstRef::Unknown)
461461
}
@@ -464,12 +464,12 @@ impl ConstRef {
464464
}
465465
ast::LiteralKind::Bool(f) => LiteralConstRef::Bool(f),
466466
_ => LiteralConstRef::Unknown,
467-
}),
467+
})),
468468
_ => {
469469
if let Some(ast_id) = ast_id {
470470
Self::Complex(ast_id)
471471
} else {
472-
Self::Scalar(LiteralConstRef::Unknown)
472+
Self::Scalar(Box::new(LiteralConstRef::Unknown))
473473
}
474474
}
475475
}

0 commit comments

Comments
 (0)