lint: Use early exit/continue

This commit is contained in:
Kurtis Rader 2016-10-29 21:20:29 -07:00
parent 9af0797334
commit 99b729eb4d

View file

@ -365,7 +365,7 @@ void pager_t::set_term_size(int w, int h) {
}
/// Try to print the list of completions l with the prefix prefix using cols as the number of
/// columns. Return true if the completion list was printed, false if the terminal is to narrow for
/// columns. Return true if the completion list was printed, false if the terminal is too narrow for
/// the specified number of columns. Always succeeds if cols is 1.
bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const comp_info_list_t &lst,
page_rendering_t *rendering, size_t suggested_start_row) const {
@ -446,7 +446,10 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
print = true;
}
if (print) {
if (!print) {
return false; // no need to continue
}
// Determine the starting and stop row.
size_t start_row = 0, stop_row = 0;
if (row_count <= term_height) {
@ -513,8 +516,8 @@ bool pager_t::completion_try_print(size_t cols, const wcstring &prefix, const co
print_max(search_field_text, highlight_modifier_force_underline,
term_width - search_field_written - 1, false, search_field);
}
}
return print;
return true;
}
page_rendering_t pager_t::render() const {
@ -717,19 +720,21 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
new_selected_completion_idx = current_col * rendering.rows + current_row;
}
if (new_selected_completion_idx != selected_completion_idx) {
if (selected_completion_idx == new_selected_completion_idx) {
return false;
}
selected_completion_idx = new_selected_completion_idx;
// Update suggested_row_start to ensure the selection is visible. suggested_row_start *
// rendering.cols is the first suggested visible completion; add the visible completion
// count to that to get the last one.
size_t visible_row_count = rendering.row_end - rendering.row_start;
if (visible_row_count > 0 && selected_completion_idx != PAGER_SELECTION_NONE) // paranoia
{
size_t row_containing_selection = this->get_selected_row(rendering);
if (visible_row_count == 0 || selected_completion_idx == PAGER_SELECTION_NONE) {
return true; // this should never happen but be paranoid
}
// Ensure our suggested row start is not past the selected row.
size_t row_containing_selection = this->get_selected_row(rendering);
if (suggested_row_start > row_containing_selection) {
suggested_row_start = row_containing_selection;
}
@ -747,12 +752,8 @@ bool pager_t::select_next_completion_in_direction(selection_direction_t directio
fully_disclosed = true;
}
}
}
return true;
} else {
return false;
}
}
size_t pager_t::visual_selected_completion_index(size_t rows, size_t cols) const {