mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Reduce size of Stmt from 144 to 120 bytes (#11051)
## Summary I happened to notice that we box `TypeParams` on `StmtClassDef` but not on `StmtFunctionDef` and wondered why, since `StmtFunctionDef` is bigger and sets the size of `Stmt`. @charliermarsh found that at the time we started boxing type params on classes, classes were the largest statement type (see #6275), but that's no longer true. So boxing type-params also on functions reduces the overall size of `Stmt`. ## Test Plan The `<=` size tests are a bit irritating (since their failure doesn't tell you the actual size), but I manually confirmed that the size is actually 120 now.
This commit is contained in:
parent
99f7f94538
commit
c80b9a4a90
4 changed files with 6 additions and 6 deletions
|
@ -158,7 +158,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
|
|||
decorator_list,
|
||||
returns.as_ref().map(AsRef::as_ref),
|
||||
parameters,
|
||||
type_params.as_ref(),
|
||||
type_params.as_deref(),
|
||||
);
|
||||
}
|
||||
if checker.source_type.is_stub() {
|
||||
|
|
|
@ -181,7 +181,7 @@ pub struct StmtFunctionDef {
|
|||
pub is_async: bool,
|
||||
pub decorator_list: Vec<Decorator>,
|
||||
pub name: Identifier,
|
||||
pub type_params: Option<TypeParams>,
|
||||
pub type_params: Option<Box<TypeParams>>,
|
||||
pub parameters: Box<Parameters>,
|
||||
pub returns: Option<Box<Expr>>,
|
||||
pub body: Vec<Stmt>,
|
||||
|
@ -4171,8 +4171,8 @@ mod tests {
|
|||
#[test]
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
fn size() {
|
||||
assert!(std::mem::size_of::<Stmt>() <= 144);
|
||||
assert!(std::mem::size_of::<StmtFunctionDef>() <= 144);
|
||||
assert!(std::mem::size_of::<Stmt>() <= 120);
|
||||
assert!(std::mem::size_of::<StmtFunctionDef>() <= 120);
|
||||
assert!(std::mem::size_of::<StmtClassDef>() <= 104);
|
||||
assert!(std::mem::size_of::<StmtTry>() <= 112);
|
||||
assert!(std::mem::size_of::<Mod>() <= 32);
|
||||
|
|
|
@ -108,7 +108,7 @@ impl<'a> ClauseHeader<'a> {
|
|||
returns,
|
||||
body: _,
|
||||
}) => {
|
||||
if let Some(type_params) = type_params.as_ref() {
|
||||
if let Some(type_params) = type_params.as_deref() {
|
||||
visit(type_params, visitor);
|
||||
}
|
||||
visit(parameters.as_ref(), visitor);
|
||||
|
|
|
@ -1738,7 +1738,7 @@ impl<'src> Parser<'src> {
|
|||
|
||||
ast::StmtFunctionDef {
|
||||
name,
|
||||
type_params,
|
||||
type_params: type_params.map(Box::new),
|
||||
parameters: Box::new(parameters),
|
||||
body,
|
||||
decorator_list,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue