Use const auto for all jobs

This commit is contained in:
Mahmoud Al-Qudsi 2019-03-20 22:37:26 -05:00
parent d4d5c03a03
commit 36f3a6d7e0
9 changed files with 19 additions and 19 deletions

View file

@ -52,7 +52,7 @@ int builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (optind == argc) {
// No jobs were specified so use the most recent (i.e., last) job.
job_t *job = nullptr;
for (auto j : jobs()) {
for (const auto &j : jobs()) {
if (j->is_stopped() && j->get_flag(job_flag_t::JOB_CONTROL) && (!j->is_completed())) {
job = j.get();
break;

View file

@ -65,7 +65,7 @@ int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Foreground jobs can be disowned.
// Even jobs that aren't under job control can be disowned!
job_t *job = nullptr;
for (auto j : jobs()) {
for (const auto &j : jobs()) {
if (j->is_constructed() && (!j->is_completed())) {
job = j.get();
break;
@ -104,7 +104,7 @@ int builtin_disown(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
}
// Disown all target jobs
for (auto j : jobs) {
for (const auto &j : jobs) {
retval |= disown_job(cmd, parser, streams, j);
}
}

View file

@ -38,7 +38,7 @@ int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
// Select last constructed job (i.e. first job in the job queue) that can be brought
// to the foreground.
for (auto j : jobs()) {
for (const auto &j : jobs()) {
if (j->is_constructed() && (!j->is_completed()) &&
((j->is_stopped() || (!j->is_foreground())) &&
j->get_flag(job_flag_t::JOB_CONTROL))) {

View file

@ -174,7 +174,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (print_last) {
// Ignore unconstructed jobs, i.e. ourself.
for (auto j : jobs()) {
for (const auto &j : jobs()) {
if (j->is_constructed() && !j->is_completed()) {
builtin_jobs_print(j.get(), mode, !streams.out_is_redirected, streams);
return STATUS_CMD_ERROR;
@ -215,7 +215,7 @@ int builtin_jobs(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
}
}
} else {
for (auto j : jobs()) {
for (const auto &j : jobs()) {
// Ignore unconstructed jobs, i.e. ourself.
if (j->is_constructed() && !j->is_completed()) {
builtin_jobs_print(j.get(), mode, !found && !streams.out_is_redirected, streams);

View file

@ -16,7 +16,7 @@
/// If a specified process has already finished but the job hasn't, parser_t::job_get_from_pid()
/// doesn't work properly, so use this function in wait command.
static job_id_t get_job_id_from_pid(pid_t pid) {
for (auto j : jobs()) {
for (const auto &j : jobs()) {
if (j->pgid == pid) {
return j->job_id;
}
@ -31,7 +31,7 @@ static job_id_t get_job_id_from_pid(pid_t pid) {
}
static bool all_jobs_finished() {
for (auto j : jobs()) {
for (const auto &j : jobs()) {
// If any job is not completed, return false.
// If there are stopped jobs, they are ignored.
if (j->is_constructed() && !j->is_completed() && !j->is_stopped()) {
@ -48,7 +48,7 @@ static bool any_jobs_finished(size_t jobs_len) {
if (jobs_len != jobs().size()) {
return true;
}
for (auto j : jobs()) {
for (const auto &j : jobs()) {
// If any job is completed, return true.
if (j->is_constructed() && (j->is_completed() || j->is_stopped())) {
return true;
@ -139,7 +139,7 @@ static bool match_pid(const wcstring &cmd, const wchar_t *proc) {
static bool find_job_by_name(const wchar_t *proc, std::vector<job_id_t> &ids) {
bool found = false;
for (const auto j : jobs()) {
for (const auto &j : jobs()) {
if (j->command_is_empty()) continue;
if (match_pid(j->command(), proc)) {

View file

@ -785,7 +785,7 @@ parse_execution_result_t parse_execution_context_t::populate_plain_process(
static uint32_t last_exec_run_counter = -1;
if (process_type == process_type_t::exec && shell_is_interactive()) {
bool have_bg = false;
for (const auto bg : jobs()) {
for (const auto &bg : jobs()) {
// The assumption here is that if it is a foreground job,
// it's related to us.
// This stops us from asking if we're doing `exec` inside a function.

View file

@ -597,7 +597,7 @@ job_t *parser_t::job_get_from_pid(pid_t pid) const {
return 0;
}
for (auto job : jobs()) {
for (const auto &job : jobs()) {
if (job->pgid == pgid) {
for (const process_ptr_t &p : job->processes) {
if (p->pid == pid) {

View file

@ -107,7 +107,7 @@ void job_t::promote() {
}
void proc_destroy() {
for (const auto job : jobs()) {
for (const auto &job : jobs()) {
debug(2, L"freeing leaked job %ls", job->command_wcstr());
}
jobs().clear();
@ -372,7 +372,7 @@ static void process_mark_finished_children(bool block_ok) {
// We got some changes. Since we last checked we received SIGCHLD, and or HUP/INT.
// Update the hup/int generations and reap any reapable processes.
for (const auto j : jobs()) {
for (const auto &j : jobs()) {
for (const auto &proc : j->processes) {
if (auto mtopic = j->reap_topic_for_process(proc.get())) {
// Update the signal hup/int gen.
@ -645,7 +645,7 @@ unsigned long proc_get_jiffies(process_t *p) {
/// Update the CPU time for all jobs.
void proc_update_jiffies() {
for (auto job : jobs()) {
for (const auto &job : jobs()) {
for (process_ptr_t &p : job->processes) {
gettimeofday(&p->last_time, 0);
p->last_jiffies = proc_get_jiffies(p.get());
@ -880,7 +880,7 @@ void job_t::continue_job(bool send_sigcont) {
void proc_sanity_check() {
const job_t *fg_job = NULL;
for (const auto j : jobs()) {
for (const auto &j : jobs()) {
if (!j->is_constructed()) continue;
// More than one foreground job?
@ -937,7 +937,7 @@ void proc_wait_any() {
}
void hup_background_jobs() {
for (auto j : jobs()) {
for (const auto &j : jobs()) {
// Make sure we don't try to SIGHUP the calling builtin
if (j->pgid == INVALID_PID || !j->get_flag(job_flag_t::JOB_CONTROL)) {
continue;

View file

@ -2229,7 +2229,7 @@ void reader_bg_job_warning() {
std::fputws(_(L"There are still jobs active:\n"), stdout);
std::fputws(_(L"\n PID Command\n"), stdout);
for (auto j : jobs()) {
for (const auto &j : jobs()) {
if (!j->is_completed()) {
std::fwprintf(stdout, L"%6d %ls\n", j->processes[0]->pid, j->command_wcstr());
}
@ -2253,7 +2253,7 @@ static void handle_end_loop() {
}
bool bg_jobs = false;
for (const auto j : jobs()) {
for (const auto &j : jobs()) {
if (!j->is_completed()) {
bg_jobs = true;
break;