Use a boxed slice for Export struct (#5887)

## Summary

The vector of names here is immutable -- we never push to it after
initialization. Boxing reduces the size of the variant from 32 bytes to
24 bytes. (See:
https://nnethercote.github.io/perf-book/type-sizes.html#boxed-slices.)
It doesn't make a difference here, since it's not the largest variant,
but it still seems like a prudent change (and I was considering adding
another field to this variant, though I may no longer do so).
This commit is contained in:
Charlie Marsh 2023-07-19 11:45:04 -04:00 committed by GitHub
parent a227775f62
commit a75a6de577
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -4562,7 +4562,9 @@ impl<'a> Checker<'a> {
self.add_binding(
id,
expr.range(),
BindingKind::Export(Export { names }),
BindingKind::Export(Export {
names: names.into_boxed_slice(),
}),
BindingFlags::empty(),
);
return;
@ -4571,7 +4573,7 @@ impl<'a> Checker<'a> {
if self
.semantic
.expr_ancestors()
.any(|expr| matches!(expr, Expr::NamedExpr(_)))
.any(|expr| expr.is_named_expr_expr())
{
self.add_binding(
id,

View file

@ -283,7 +283,7 @@ impl<'a> FromIterator<Binding<'a>> for Bindings<'a> {
#[derive(Debug, Clone)]
pub struct Export<'a> {
/// The names of the bindings exported via `__all__`.
pub names: Vec<&'a str>,
pub names: Box<[&'a str]>,
}
/// A binding for an `import`, keyed on the name to which the import is bound.