lint: Use early exit/continue

This commit is contained in:
Kurtis Rader 2016-10-30 15:37:16 -07:00
parent 6192e2453e
commit 6c3900ff64

View file

@ -435,7 +435,7 @@ struct find_job_data_t {
/// The following function is invoked on the main thread, because the job list is not thread safe.
/// It should search the job list for something matching the given proc, and then return 1 to stop
/// the search, 0 to continue it .
/// the search, 0 to continue it.
static int find_job(const struct find_job_data_t *info) {
ASSERT_IS_MAIN_THREAD();
@ -494,7 +494,10 @@ static int find_job(const struct find_job_data_t *info) {
found = 1;
}
if (!found) {
if (found) {
return found;
}
job_iterator_t jobs;
while ((j = jobs.next())) {
if (j->command_is_empty()) continue;
@ -511,7 +514,10 @@ static int find_job(const struct find_job_data_t *info) {
}
}
if (!found) {
if (found) {
return found;
}
jobs.reset();
while ((j = jobs.next())) {
process_t *p;
@ -522,8 +528,7 @@ static int find_job(const struct find_job_data_t *info) {
size_t offset;
if (match_pid(p->actual_cmd, proc, &offset)) {
if (flags & EXPAND_FOR_COMPLETIONS) {
append_completion(&completions,
wcstring(p->actual_cmd, offset + wcslen(proc)),
append_completion(&completions, wcstring(p->actual_cmd, offset + wcslen(proc)),
COMPLETE_CHILD_PROCESS_DESC, 0);
} else {
append_completion(&completions, to_string<long>(p->pid), L"", 0);
@ -532,8 +537,6 @@ static int find_job(const struct find_job_data_t *info) {
}
}
}
}
}
return found;
}
@ -746,13 +749,15 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
for (long i = last_idx - 1; (i >= 0) && is_ok && !empty; i--) {
const wchar_t c = instr.at(i);
if ((c == VARIABLE_EXPAND) || (c == VARIABLE_EXPAND_SINGLE)) {
size_t start_pos = i + 1;
size_t stop_pos;
if (c != VARIABLE_EXPAND && c != VARIABLE_EXPAND_SINGLE) {
continue;
}
long var_len;
int is_single = (c == VARIABLE_EXPAND_SINGLE);
size_t start_pos = i + 1;
size_t stop_pos = start_pos;
stop_pos = start_pos;
while (stop_pos < insize) {
const wchar_t nc = instr.at(stop_pos);
if (nc == VARIABLE_EXPAND_EMPTY) {
@ -797,8 +802,8 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
size_t bad_pos;
all_vars = 0;
const wchar_t *in = instr.c_str();
bad_pos = parse_slice(in + slice_start, &slice_end, var_idx_list,
var_pos_list, var_item_list.size());
bad_pos = parse_slice(in + slice_start, &slice_end, var_idx_list, var_pos_list,
var_item_list.size());
if (bad_pos != 0) {
append_syntax_error(errors, stop_pos + bad_pos, L"Invalid index value");
is_ok = false;
@ -836,7 +841,10 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
}
}
if (is_ok) {
if (!is_ok) {
return is_ok;
}
if (is_single) {
wcstring res(instr, 0, i);
if (i > 0) {
@ -861,7 +869,7 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
} else {
for (size_t j = 0; j < var_item_list.size(); j++) {
const wcstring &next = var_item_list.at(j);
if (is_ok && (i == 0) && stop_pos == insize) {
if (is_ok && i == 0 && stop_pos == insize) {
append_completion(out, next);
} else {
if (is_ok) {
@ -883,7 +891,6 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
}
}
}
}
return is_ok;
}
@ -934,7 +941,6 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
return is_ok;
}
}
}
if (!empty) {
append_completion(out, instr);
@ -1543,8 +1549,11 @@ static std::string escape_single_quoted_hack_hack_hack_hack(const char *str) {
bool fish_xdm_login_hack_hack_hack_hack(std::vector<std::string> *cmds, int argc,
const char *const *argv) {
if (!cmds || cmds->size() != 1) {
return false;
}
bool result = false;
if (cmds && cmds->size() == 1) {
const std::string &cmd = cmds->at(0);
if (cmd == "exec \"${@}\"" || cmd == "exec \"$@\"") {
// We're going to construct a new command that starts with exec, and then has the
@ -1561,7 +1570,6 @@ bool fish_xdm_login_hack_hack_hack_hack(std::vector<std::string> *cmds, int argc
cmds->at(0) = new_cmd;
result = true;
}
}
return result;
}