mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Optimize get_deferred_process() traversal
This commit is contained in:
parent
aafd706a34
commit
3c537bfa65
1 changed files with 8 additions and 9 deletions
17
src/exec.cpp
17
src/exec.cpp
|
@ -993,21 +993,20 @@ static bool exec_process_in_job(parser_t &parser, process_t *p, std::shared_ptr<
|
|||
// This should show the output as it comes, not buffer until the end.
|
||||
// Any such process (only one per job) will be called the "deferred" process.
|
||||
static process_t *get_deferred_process(const shared_ptr<job_t> &j) {
|
||||
process_t *last_internal = nullptr;
|
||||
for (const auto &p : j->processes) {
|
||||
// By enumerating in reverse order, we can avoid walking the entire list
|
||||
for (auto i = j->processes.rbegin(); i != j->processes.rend(); ++i) {
|
||||
const auto &p = *i;
|
||||
if (p->type == process_type_t::exec) {
|
||||
// No tail reordering for execs.
|
||||
return nullptr;
|
||||
} else if (p->type != process_type_t::external) {
|
||||
last_internal = p.get();
|
||||
if (p->is_last_in_job) {
|
||||
return nullptr;
|
||||
}
|
||||
return p.get();
|
||||
}
|
||||
}
|
||||
if (last_internal && !last_internal->is_last_in_job) {
|
||||
// This is the last internal process, and it pipes to an external process.
|
||||
return last_internal;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool exec_job(parser_t &parser, shared_ptr<job_t> j) {
|
||||
|
|
Loading…
Reference in a new issue