mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
Replace some simple loops with STL algorithms
src/builtins/argparce.cpp: replace_if src/builtins/set.cpp: count_if src/topic_monitor.h: any_of
This commit is contained in:
parent
7d1d43744a
commit
4f835a0f0f
3 changed files with 10 additions and 16 deletions
|
@ -692,12 +692,10 @@ static void set_argparse_result_vars(env_stack_t &vars, const argparse_cmd_opts_
|
|||
vars.set(var_name_prefix + opt_spec->short_flag, ENV_LOCAL, opt_spec->vals);
|
||||
}
|
||||
if (!opt_spec->long_flag.empty()) {
|
||||
// We do a simple replacement of all non alphanum chars rather than calling
|
||||
// We do a simple replacement of punctuation chars rather than calling
|
||||
// escape_string(long_flag, 0, STRING_STYLE_VAR).
|
||||
wcstring long_flag = opt_spec->long_flag;
|
||||
for (auto &pos : long_flag) {
|
||||
if (!iswalnum(pos)) pos = L'_';
|
||||
}
|
||||
std::replace_if(long_flag.begin(), long_flag.end(), std::iswpunct, L'_');
|
||||
vars.set(var_name_prefix + long_flag, ENV_LOCAL, opt_spec->vals);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -484,15 +484,12 @@ static int builtin_set_query(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
|
|||
return STATUS_CMD_ERROR;
|
||||
}
|
||||
|
||||
if (split->indexes.empty()) {
|
||||
// No indexes, just increment if our variable is missing.
|
||||
if (!split->var) retval++;
|
||||
} else {
|
||||
if (split->indexes.empty() && !split->var) retval++; // No indicies, increment if missing
|
||||
else {
|
||||
// Increment for every index out of range.
|
||||
long varsize = split->varsize();
|
||||
for (long idx : split->indexes) {
|
||||
if (idx < 1 || idx > varsize) retval++;
|
||||
}
|
||||
retval += std::count_if(split->indexes.begin(), split->indexes.end(),
|
||||
[varsize](long i) { return (i < 1 || i > varsize); });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -102,11 +102,10 @@ class generation_list_t {
|
|||
|
||||
/// \return whether any topic is valid.
|
||||
bool any_valid() const {
|
||||
bool valid = false;
|
||||
for (auto gen : as_array()) {
|
||||
if (gen != invalid_generation) valid = true;
|
||||
}
|
||||
return valid;
|
||||
auto arr = as_array();
|
||||
return std::any_of(arr.cbegin(), arr.cend(), [](generation_t gen) {
|
||||
return gen != invalid_generation;
|
||||
});
|
||||
}
|
||||
|
||||
bool operator==(const generation_list_t &rhs) const {
|
||||
|
|
Loading…
Reference in a new issue