Use Vec for Closure captures (#10940)

# Description
Changes the `captures` field in `Closure` from a `HashMap` to a `Vec`
and makes `Stack::captures_to_stack` take an owned `Vec` instead of a
borrowed `HashMap`.

This eliminates the conversion to a `Vec` inside `captures_to_stack` and
makes it possible to avoid clones altogether when using an owned
`Closure` (which is the case for most commands). Additionally, using a
`Vec` reduces the size of `Value` by 8 bytes (down to 72).

# User-Facing Changes
Breaking API change for `nu-protocol`.
This commit is contained in:
Ian Manske
2023-11-07 23:43:28 +00:00
committed by GitHub
parent 7a3cbf43e8
commit 60da7abbc7
33 changed files with 46 additions and 59 deletions

View File

@ -61,7 +61,7 @@ impl<'a> StyleComputer<'a> {
let block = self.engine_state.get_block(val.block_id).clone();
// Because captures_to_stack() clones, we don't need to use with_env() here
// (contrast with_env() usage in `each` or `do`).
let mut stack = self.stack.captures_to_stack(&val.captures);
let mut stack = self.stack.captures_to_stack(val.captures.clone());
// Support 1-argument blocks as well as 0-argument blocks.
if let Some(var) = block.signature.get_positional(0) {