mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 21:33:09 +00:00
Switch some loops in handle_completions to C++11 range-based for looops
This commit is contained in:
parent
cdfdc994f1
commit
0b2d8fd37e
1 changed files with 6 additions and 7 deletions
|
@ -1391,8 +1391,7 @@ static bool handle_completions(const std::vector<completion_t> &comp,
|
||||||
// Determine whether we are going to replace the token or not. If any commands of the best
|
// Determine whether we are going to replace the token or not. If any commands of the best
|
||||||
// type do not require replacement, then ignore all those that want to use replacement.
|
// type do not require replacement, then ignore all those that want to use replacement.
|
||||||
bool will_replace_token = true;
|
bool will_replace_token = true;
|
||||||
for (size_t i = 0; i < comp.size(); i++) {
|
for (const completion_t &el : comp) {
|
||||||
const completion_t &el = comp.at(i);
|
|
||||||
if (el.match.type <= best_match_type && !(el.flags & COMPLETE_REPLACES_TOKEN)) {
|
if (el.match.type <= best_match_type && !(el.flags & COMPLETE_REPLACES_TOKEN)) {
|
||||||
will_replace_token = false;
|
will_replace_token = false;
|
||||||
break;
|
break;
|
||||||
|
@ -1402,8 +1401,7 @@ static bool handle_completions(const std::vector<completion_t> &comp,
|
||||||
// Decide which completions survived. There may be a lot of them; it would be nice if we could
|
// Decide which completions survived. There may be a lot of them; it would be nice if we could
|
||||||
// figure out how to avoid copying them here.
|
// figure out how to avoid copying them here.
|
||||||
std::vector<completion_t> surviving_completions;
|
std::vector<completion_t> surviving_completions;
|
||||||
for (size_t i = 0; i < comp.size(); i++) {
|
for (const completion_t &el : comp) {
|
||||||
const completion_t &el = comp.at(i);
|
|
||||||
// Ignore completions with a less suitable match type than the best.
|
// Ignore completions with a less suitable match type than the best.
|
||||||
if (el.match.type > best_match_type) continue;
|
if (el.match.type > best_match_type) continue;
|
||||||
|
|
||||||
|
@ -1424,12 +1422,13 @@ static bool handle_completions(const std::vector<completion_t> &comp,
|
||||||
wcstring common_prefix;
|
wcstring common_prefix;
|
||||||
complete_flags_t flags = 0;
|
complete_flags_t flags = 0;
|
||||||
bool prefix_is_partial_completion = false;
|
bool prefix_is_partial_completion = false;
|
||||||
for (size_t i = 0; i < surviving_completions.size(); i++) {
|
bool first = true;
|
||||||
const completion_t &el = surviving_completions.at(i);
|
for (const completion_t &el : surviving_completions) {
|
||||||
if (i == 0) {
|
if (first) {
|
||||||
// First entry, use the whole string.
|
// First entry, use the whole string.
|
||||||
common_prefix = el.completion;
|
common_prefix = el.completion;
|
||||||
flags = el.flags;
|
flags = el.flags;
|
||||||
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
// Determine the shared prefix length.
|
// Determine the shared prefix length.
|
||||||
size_t idx, max = mini(common_prefix.size(), el.completion.size());
|
size_t idx, max = mini(common_prefix.size(), el.completion.size());
|
||||||
|
|
Loading…
Reference in a new issue