Merge pull request #254 from nushell/iter_perf

Some iter perf improvements
This commit is contained in:
JT 2021-10-26 16:28:42 +13:00 committed by GitHub
commit 29dde84394
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 32 deletions

View file

@ -56,18 +56,17 @@ impl Command for For {
.expect("internal error: expected block");
let engine_state = engine_state.clone();
let block = engine_state.get_block(block_id);
let block = engine_state.get_block(block_id).clone();
let mut stack = stack.collect_captures(&block.captures);
match values {
Value::List { vals, .. } => Ok(vals
.into_iter()
.map(move |x| {
let mut stack = stack.clone();
stack.add_var(var_id, x);
let block = engine_state.get_block(block_id);
match eval_block(&engine_state, &mut stack, block, PipelineData::new()) {
//let block = engine_state.get_block(block_id);
match eval_block(&engine_state, &mut stack, &block, PipelineData::new()) {
Ok(pipeline_data) => pipeline_data.into_value(),
Err(error) => Value::Error { error },
}
@ -78,8 +77,8 @@ impl Command for For {
.map(move |x| {
stack.add_var(var_id, x);
let block = engine_state.get_block(block_id);
match eval_block(&engine_state, &mut stack, block, PipelineData::new()) {
//let block = engine_state.get_block(block_id);
match eval_block(&engine_state, &mut stack, &block, PipelineData::new()) {
Ok(pipeline_data) => pipeline_data.into_value(),
Err(error) => Value::Error { error },
}
@ -88,7 +87,7 @@ impl Command for For {
x => {
stack.add_var(var_id, x);
eval_block(&engine_state, &mut stack, block, PipelineData::new())
eval_block(&engine_state, &mut stack, &block, PipelineData::new())
}
}
}

View file

@ -64,7 +64,7 @@ impl Command for Each {
let numbered = call.has_flag("numbered");
let engine_state = engine_state.clone();
let block = engine_state.get_block(block_id);
let block = engine_state.get_block(block_id).clone();
let mut stack = stack.collect_captures(&block.captures);
let span = call.head;
@ -73,10 +73,6 @@ impl Command for Each {
.into_range_iter()?
.enumerate()
.map(move |(idx, x)| {
let block = engine_state.get_block(block_id);
let mut stack = stack.clone();
if let Some(var) = block.signature.get_positional(0) {
if let Some(var_id) = &var.var_id {
if numbered {
@ -100,21 +96,16 @@ impl Command for Each {
}
}
match eval_block(&engine_state, &mut stack, block, PipelineData::new()) {
Ok(v) => v,
Err(error) => Value::Error { error }.into_pipeline_data(),
match eval_block(&engine_state, &mut stack, &block, PipelineData::new()) {
Ok(v) => v.into_value(),
Err(error) => Value::Error { error },
}
})
.flatten()
.into_pipeline_data()),
PipelineData::Value(Value::List { vals: val, .. }) => Ok(val
.into_iter()
.enumerate()
.map(move |(idx, x)| {
let block = engine_state.get_block(block_id);
let mut stack = stack.clone();
if let Some(var) = block.signature.get_positional(0) {
if let Some(var_id) = &var.var_id {
if numbered {
@ -138,20 +129,15 @@ impl Command for Each {
}
}
match eval_block(&engine_state, &mut stack, block, PipelineData::new()) {
Ok(v) => v,
Err(error) => Value::Error { error }.into_pipeline_data(),
match eval_block(&engine_state, &mut stack, &block, PipelineData::new()) {
Ok(v) => v.into_value(),
Err(error) => Value::Error { error },
}
})
.flatten()
.into_pipeline_data()),
PipelineData::Stream(stream) => Ok(stream
.enumerate()
.map(move |(idx, x)| {
let block = engine_state.get_block(block_id);
let mut stack = stack.clone();
if let Some(var) = block.signature.get_positional(0) {
if let Some(var_id) = &var.var_id {
if numbered {
@ -175,12 +161,11 @@ impl Command for Each {
}
}
match eval_block(&engine_state, &mut stack, block, PipelineData::new()) {
Ok(v) => v,
Err(error) => Value::Error { error }.into_pipeline_data(),
match eval_block(&engine_state, &mut stack, &block, PipelineData::new()) {
Ok(v) => v.into_value(),
Err(error) => Value::Error { error },
}
})
.flatten()
.into_pipeline_data()),
PipelineData::Value(Value::Record { cols, vals, .. }) => {
let mut output_cols = vec![];