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:
Charlie Marsh 2024-02-08 18:53:13 -08:00 committed by GitHub
parent bd8123c0d8
commit 49fe1b85f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
78 changed files with 326 additions and 258 deletions

View file

@ -1406,8 +1406,18 @@ NotTest<Goal>: crate::parser::ParenthesizedExpr = {
Comparison<Goal>: crate::parser::ParenthesizedExpr = {
<location:@L> <left:Expression<"all">> <comparisons:(CompOp Expression<"all">)+> <end_location:@R> => {
let (ops, comparators) = comparisons.into_iter().map(|(op, comparator)| (op, ast::Expr::from(comparator))).unzip();
ast::ExprCompare { left: Box::new(left.into()), ops, comparators, range: (location..end_location).into() }.into()
let mut ops = Vec::with_capacity(comparisons.len());
let mut comparators = Vec::with_capacity(comparisons.len());
for (op, comparator) in comparisons {
ops.push(op);
comparators.push(comparator.into());
}
ast::ExprCompare {
left: Box::new(left.into()),
ops: ops.into_boxed_slice(),
comparators: comparators.into_boxed_slice(),
range: (location..end_location).into(),
}.into()
},
Expression<Goal>,
};
@ -1880,8 +1890,8 @@ Arguments: ast::Arguments = {
<location:@L> "(" <e: Comma<FunctionArgument>> ")" <end_location:@R> =>? {
let ArgumentList { args, keywords } = parse_arguments(e)?;
Ok(ast::Arguments {
args,
keywords,
args: args.into_boxed_slice(),
keywords: keywords.into_boxed_slice(),
range: (location..end_location).into()
})
}