mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-22 03:14:41 +00:00
Reduce size of Expr
from 80 to 64 bytes (#9900)
## Summary This PR reduces the size of `Expr` from 80 to 64 bytes, by reducing the sizes of... - `ExprCall` from 72 to 56 bytes, by using boxed slices for `Arguments`. - `ExprCompare` from 64 to 48 bytes, by using boxed slices for its various vectors. In testing, the parser gets a bit faster, and the linter benchmarks improve quite a bit.
This commit is contained in:
parent
bd8123c0d8
commit
49fe1b85f2
78 changed files with 326 additions and 258 deletions
|
@ -894,8 +894,8 @@ impl From<ExprYieldFrom> for Expr {
|
|||
pub struct ExprCompare {
|
||||
pub range: TextRange,
|
||||
pub left: Box<Expr>,
|
||||
pub ops: Vec<CmpOp>,
|
||||
pub comparators: Vec<Expr>,
|
||||
pub ops: Box<[CmpOp]>,
|
||||
pub comparators: Box<[Expr]>,
|
||||
}
|
||||
|
||||
impl From<ExprCompare> for Expr {
|
||||
|
@ -2987,8 +2987,8 @@ pub struct ParameterWithDefault {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Arguments {
|
||||
pub range: TextRange,
|
||||
pub args: Vec<Expr>,
|
||||
pub keywords: Vec<Keyword>,
|
||||
pub args: Box<[Expr]>,
|
||||
pub keywords: Box<[Keyword]>,
|
||||
}
|
||||
|
||||
/// An entry in the argument list of a function call.
|
||||
|
@ -3894,10 +3894,42 @@ mod tests {
|
|||
assert!(std::mem::size_of::<StmtFunctionDef>() <= 144);
|
||||
assert!(std::mem::size_of::<StmtClassDef>() <= 104);
|
||||
assert!(std::mem::size_of::<StmtTry>() <= 112);
|
||||
// 80 for Rustc < 1.76
|
||||
assert!(matches!(std::mem::size_of::<Expr>(), 72 | 80));
|
||||
assert!(std::mem::size_of::<Mod>() <= 32);
|
||||
// 96 for Rustc < 1.76
|
||||
assert!(matches!(std::mem::size_of::<Pattern>(), 88 | 96));
|
||||
assert!(std::mem::size_of::<Mod>() <= 32);
|
||||
|
||||
assert_eq!(std::mem::size_of::<Expr>(), 64);
|
||||
assert_eq!(std::mem::size_of::<ExprAttribute>(), 56);
|
||||
assert_eq!(std::mem::size_of::<ExprAwait>(), 16);
|
||||
assert_eq!(std::mem::size_of::<ExprBinOp>(), 32);
|
||||
assert_eq!(std::mem::size_of::<ExprBoolOp>(), 40);
|
||||
assert_eq!(std::mem::size_of::<ExprBooleanLiteral>(), 12);
|
||||
assert_eq!(std::mem::size_of::<ExprBytesLiteral>(), 40);
|
||||
assert_eq!(std::mem::size_of::<ExprCall>(), 56);
|
||||
assert_eq!(std::mem::size_of::<ExprCompare>(), 48);
|
||||
assert_eq!(std::mem::size_of::<ExprDict>(), 56);
|
||||
assert_eq!(std::mem::size_of::<ExprDictComp>(), 48);
|
||||
assert_eq!(std::mem::size_of::<ExprEllipsisLiteral>(), 8);
|
||||
assert_eq!(std::mem::size_of::<ExprFString>(), 48);
|
||||
assert_eq!(std::mem::size_of::<ExprGeneratorExp>(), 40);
|
||||
assert_eq!(std::mem::size_of::<ExprIfExp>(), 32);
|
||||
assert_eq!(std::mem::size_of::<ExprIpyEscapeCommand>(), 32);
|
||||
assert_eq!(std::mem::size_of::<ExprLambda>(), 24);
|
||||
assert_eq!(std::mem::size_of::<ExprList>(), 40);
|
||||
assert_eq!(std::mem::size_of::<ExprListComp>(), 40);
|
||||
assert_eq!(std::mem::size_of::<ExprName>(), 40);
|
||||
assert_eq!(std::mem::size_of::<ExprNamedExpr>(), 24);
|
||||
assert_eq!(std::mem::size_of::<ExprNoneLiteral>(), 8);
|
||||
assert_eq!(std::mem::size_of::<ExprNumberLiteral>(), 32);
|
||||
assert_eq!(std::mem::size_of::<ExprSet>(), 32);
|
||||
assert_eq!(std::mem::size_of::<ExprSetComp>(), 40);
|
||||
assert_eq!(std::mem::size_of::<ExprSlice>(), 32);
|
||||
assert_eq!(std::mem::size_of::<ExprStarred>(), 24);
|
||||
assert_eq!(std::mem::size_of::<ExprStringLiteral>(), 48);
|
||||
assert_eq!(std::mem::size_of::<ExprSubscript>(), 32);
|
||||
assert_eq!(std::mem::size_of::<ExprTuple>(), 40);
|
||||
assert_eq!(std::mem::size_of::<ExprUnaryOp>(), 24);
|
||||
assert_eq!(std::mem::size_of::<ExprYield>(), 16);
|
||||
assert_eq!(std::mem::size_of::<ExprYieldFrom>(), 16);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue