From a75a6de5778c788fb6e31a838b8468cfb569e1b2 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 19 Jul 2023 11:45:04 -0400 Subject: [PATCH] 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). --- crates/ruff/src/checkers/ast/mod.rs | 6 ++++-- crates/ruff_python_semantic/src/binding.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/ruff/src/checkers/ast/mod.rs b/crates/ruff/src/checkers/ast/mod.rs index a628befeb7..45811ad6b2 100644 --- a/crates/ruff/src/checkers/ast/mod.rs +++ b/crates/ruff/src/checkers/ast/mod.rs @@ -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, diff --git a/crates/ruff_python_semantic/src/binding.rs b/crates/ruff_python_semantic/src/binding.rs index 45002b8700..67498862b8 100644 --- a/crates/ruff_python_semantic/src/binding.rs +++ b/crates/ruff_python_semantic/src/binding.rs @@ -283,7 +283,7 @@ impl<'a> FromIterator> 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.