Merge pull request #36393 from tcoyvwac/fix/prefer-standard-algorithms-std-transform-storages

Minor refactor to prefer C++ Standard Algorithms
This commit is contained in:
Antonio Andelic 2022-04-20 08:42:54 +02:00 committed by GitHub
commit f0774ca9ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,11 +83,11 @@ static bool extractPathImpl(const IAST & elem, Paths & res, ContextPtr context,
if (function->name == "and")
{
for (const auto & child : function->arguments->children)
if (extractPathImpl(*child, res, context, allow_unrestricted))
return true;
return false;
const auto & children = function->arguments->children;
return std::any_of(
std::begin(children),
std::end(children),
[&](const auto & child) { return extractPathImpl(*child, res, context, allow_unrestricted); });
}
const auto & args = function->arguments->as<ASTExpressionList &>();
@ -136,8 +136,11 @@ static bool extractPathImpl(const IAST & elem, Paths & res, ContextPtr context,
}
else if (Tuple tuple; literal->value.tryGet(tuple))
{
for (auto element : tuple)
res.emplace_back(element.safeGet<String>(), ZkPathType::Exact);
std::transform(
std::begin(tuple),
std::end(tuple),
std::back_inserter(res),
[](auto element) { return std::make_pair(element.template safeGet<String>(), ZkPathType::Exact); });
}
else
return false;
@ -286,9 +289,12 @@ void StorageSystemZooKeeper::fillData(MutableColumns & res_columns, ContextPtr c
}
std::vector<std::future<Coordination::GetResponse>> futures;
futures.reserve(nodes.size());
for (const String & node : nodes)
futures.push_back(zookeeper->asyncTryGet(path_part + '/' + node));
futures.reserve(std::size(nodes));
std::transform(
std::begin(nodes),
std::end(nodes),
std::back_inserter(futures),
[&zookeeper, &path_part](const String & node) { return zookeeper->asyncTryGet(path_part + '/' + node); });
for (size_t i = 0, size = nodes.size(); i < size; ++i)
{