forked from extern/nushell
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:
@ -44,7 +44,7 @@ impl Command for Collect {
|
||||
let capture_block: Closure = call.req(engine_state, stack, 0)?;
|
||||
|
||||
let block = engine_state.get_block(capture_block.block_id).clone();
|
||||
let mut stack_captures = stack.captures_to_stack(&capture_block.captures);
|
||||
let mut stack_captures = stack.captures_to_stack(capture_block.captures.clone());
|
||||
|
||||
let metadata = input.metadata();
|
||||
let input: Value = input.into_value(call.head);
|
||||
@ -71,8 +71,8 @@ impl Command for Collect {
|
||||
redirect_env(engine_state, stack, &stack_captures);
|
||||
// for when we support `data | let x = $in;`
|
||||
// remove the variables added earlier
|
||||
for var_id in capture_block.captures.keys() {
|
||||
stack_captures.remove_var(*var_id);
|
||||
for (var_id, _) in capture_block.captures {
|
||||
stack_captures.remove_var(var_id);
|
||||
}
|
||||
if let Some(u) = saved_positional {
|
||||
stack_captures.remove_var(u);
|
||||
|
@ -72,7 +72,7 @@ impl Command for Do {
|
||||
let capture_errors = call.has_flag("capture-errors");
|
||||
let has_env = call.has_flag("env");
|
||||
|
||||
let mut callee_stack = caller_stack.captures_to_stack(&block.captures);
|
||||
let mut callee_stack = caller_stack.captures_to_stack(block.captures);
|
||||
let block = engine_state.get_block(block.block_id);
|
||||
|
||||
let params: Vec<_> = block
|
||||
|
Reference in New Issue
Block a user