Fix perf regression with stmts (#650)

This commit is contained in:
JT 2022-01-03 07:18:48 +11:00 committed by GitHub
parent c9dcd212ba
commit 354d51a3a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -418,52 +418,57 @@ pub fn eval_block(
} }
if stmt_idx < (num_stmts) - 1 { if stmt_idx < (num_stmts) - 1 {
// Drain the input to the screen via tabular output match input {
let config = stack.get_config().unwrap_or_default(); PipelineData::Value(Value::Nothing { .. }, ..) => {}
_ => {
// Drain the input to the screen via tabular output
let config = stack.get_config().unwrap_or_default();
match engine_state.find_decl("table".as_bytes()) { match engine_state.find_decl("table".as_bytes()) {
Some(decl_id) => { Some(decl_id) => {
let table = engine_state.get_decl(decl_id).run( let table = engine_state.get_decl(decl_id).run(
engine_state, engine_state,
stack, stack,
&Call::new(), &Call::new(),
input, input,
)?; )?;
for item in table { for item in table {
let stdout = std::io::stdout(); let stdout = std::io::stdout();
if let Value::Error { error } = item { if let Value::Error { error } = item {
return Err(error); return Err(error);
}
let mut out = item.into_string("\n", &config);
out.push('\n');
match stdout.lock().write_all(out.as_bytes()) {
Ok(_) => (),
Err(err) => eprintln!("{}", err),
};
}
} }
None => {
for item in input {
let stdout = std::io::stdout();
let mut out = item.into_string("\n", &config); if let Value::Error { error } = item {
out.push('\n'); return Err(error);
}
match stdout.lock().write_all(out.as_bytes()) { let mut out = item.into_string("\n", &config);
Ok(_) => (), out.push('\n');
Err(err) => eprintln!("{}", err),
};
}
}
None => {
for item in input {
let stdout = std::io::stdout();
if let Value::Error { error } = item { match stdout.lock().write_all(out.as_bytes()) {
return Err(error); Ok(_) => (),
Err(err) => eprintln!("{}", err),
};
}
} }
};
let mut out = item.into_string("\n", &config);
out.push('\n');
match stdout.lock().write_all(out.as_bytes()) {
Ok(_) => (),
Err(err) => eprintln!("{}", err),
};
}
} }
}; }
input = PipelineData::new(Span { start: 0, end: 0 }) input = PipelineData::new(Span { start: 0, end: 0 })
} }