Replace a few loops with ranges

This commit is contained in:
Maxime Coste 2018-07-26 21:04:02 +10:00
parent 0919679e0d
commit 737807dde2
3 changed files with 9 additions and 12 deletions

View File

@ -273,12 +273,9 @@ public:
if (not overlaps(display_buffer.range(), range))
return;
Vector<Face> faces(m_faces.size());
for (int f = 0; f < m_faces.size(); ++f)
{
if (not m_faces[f].second.empty())
faces[f] = context.context.faces()[m_faces[f].second];
}
const auto faces = m_faces | transform([&faces = context.context.faces()](auto&& spec) {
return spec.second.empty() ? Face{} : faces[spec.second];
}) | gather<Vector<Face>>();
auto& matches = get_matches(context.context.buffer(), display_buffer.range(), range);
kak_assert(matches.size() % m_faces.size() == 0);

View File

@ -899,10 +899,6 @@ int main(int argc, char* argv[])
set_signal_handler(SIGINT, [](int){});
set_signal_handler(SIGCHLD, [](int){});
Vector<String> params;
for (int i = 1; i < argc; ++i)
params.emplace_back(argv[i]);
const ParameterDesc param_desc{
SwitchMap{ { "c", { true, "connect to given session" } },
{ "e", { true, "execute argument on client initialisation" } },
@ -936,7 +932,11 @@ int main(int argc, char* argv[])
return 0;
};
if (contains(ConstArrayView<char*>{argv+1, (size_t)argc-1}, "--help"_sv))
const auto params = ArrayView<char*>{argv+1, argv + argc}
| transform([](auto* s) { return String{s}; })
| gather<Vector<String>>();
if (contains(params, "--help"_sv))
return show_usage();
ParametersParser parser{params, param_desc};

View File

@ -167,7 +167,7 @@ String build_autoinfo_for_mapping(Context& context, KeymapMode mode,
{
String keys = join(built_in.keys |
filter([&](Key k){ return not keymaps.is_mapped(k, mode); }) |
transform([](Key k) { return key_to_str(k); }),
transform(key_to_str),
',', false);
if (not keys.empty())
descs.emplace_back(std::move(keys), built_in.docstring);