Skip to content

Commit

Permalink
clang-tidy: simplify some algorithms
Browse files Browse the repository at this point in the history
Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Dec 10, 2024
1 parent e87ffff commit d0ce8c8
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pdns/arguments.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool ArgvMap::contains(const string& var, const string& val)
vector<string> parts;

stringtok(parts, param->second, ", \t");
return std::any_of(parts.begin(), parts.end(), [&](const std::string& str) { return str == val; });
return std::find(parts.begin(), parts.end(), val) != parts.end();
}

string ArgvMap::helpstring(string prefix)
Expand Down
10 changes: 4 additions & 6 deletions pdns/auth-secondarycommunicator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "dnssecinfra.hh"
#include "dnsseckeeper.hh"
#include "base32.hh"
#include <boost/range/algorithm_ext.hpp>
#include <cerrno>
#include "communicator.hh"
#include <set>
Expand Down Expand Up @@ -490,12 +491,9 @@ void CommunicatorClass::ixfrSuck(const DNSName& domain, const TSIGTriplet& tt, c
}
}
// O(N^2)!
rrset.erase(remove_if(rrset.begin(), rrset.end(),
[&g](const DNSRecord& dr) {
return count(g.second.first.cbegin(),
g.second.first.cend(), dr);
}),
rrset.end());
boost::range::remove_erase_if(rrset, [&g](const auto& dnsr) {
return boost::algorithm::any_of_equal(g.second.first, dnsr);
});
// the DNSRecord== operator compares on name, type, class and lowercase content representation

for (const auto& x : g.second.second) {
Expand Down
3 changes: 1 addition & 2 deletions pdns/dnsbulktest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ try
pos=split.second.find('/');
if(pos != string::npos) // alexa has whole urls in the list now.
split.second.resize(pos);
if(find_if(split.second.begin(), split.second.end(), isalpha) == split.second.end())
{
if (std::none_of(split.second.begin(), split.second.end(), isalpha)) {
continue; // this was an IP address
}
domains.push_back(TypedQuery(split.second, qtype));
Expand Down
4 changes: 3 additions & 1 deletion pdns/dnsdistdist/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <thread>
#include <vector>

#include <boost/range/algorithm_ext.hpp>

#include "dnsdist.hh"
#include "dnsdist-backend.hh"
#include "dnsdist-cache.hh"
Expand Down Expand Up @@ -760,7 +762,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
}

dnsdist::configuration::updateRuntimeConfiguration([&server](dnsdist::configuration::RuntimeConfiguration& config) {
config.d_backends.erase(std::remove(config.d_backends.begin(), config.d_backends.end(), server), config.d_backends.end());
boost::range::remove_erase(config.d_backends, server);
});

server->stop();
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-protocols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const std::array<std::string, Protocol::s_numberOfProtocols> Protocol::s_prettyN

Protocol::Protocol(const std::string& protocol)
{
const auto& namesIt = std::find(s_names.begin(), s_names.end(), protocol);
auto namesIt = std::find(s_names.begin(), s_name.end(), protocol);
if (namesIt == s_names.end()) {
throw std::runtime_error("Unknown protocol name: '" + protocol + "'");
}
Expand Down
14 changes: 1 addition & 13 deletions pdns/recursordist/syncres.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6266,19 +6266,7 @@ bool SyncRes::answerIsNOData(uint16_t requestedType, int rcode, const std::vecto
return false;
}

// NOLINTNEXTLINE(readability-use-anyofallof)
for (const auto& rec : records) {
if (rec.d_place == DNSResourceRecord::ANSWER && rec.d_type == requestedType) {
/* we have a record, of the right type, in the right section */
return false;
}
}
return true;
#if 0
// This code should be equivalent to the code above, clang-tidy prefers any_of()
// I have doubts if that is easier to read
return !std::any_of(records.begin(), records.end(), [=](const DNSRecord& rec) {
return std::none_of(records.begin(), records.end(), [=](const auto& rec) {
return rec.d_place == DNSResourceRecord::ANSWER && rec.d_type == requestedType;
});
#endif
}
6 changes: 4 additions & 2 deletions pdns/rfc2136handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,12 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr,
bool foundDeeper = false, foundOtherWithSameName = false;
di->backend->listSubZone(rr->d_name, di->id);
while (di->backend->get(rec)) {
if (rec.qname == rr->d_name && !count(recordsToDelete.begin(), recordsToDelete.end(), rec))
if (rec.qname == rr->d_name && count(recordsToDelete.begin(), recordsToDelete.end(), rec) == 0) {
foundOtherWithSameName = true;
if (rec.qname != rr->d_name && rec.qtype.getCode() != QType::NS) //Skip NS records, as this would be a delegate that we can ignore as this does not require us to create a ENT
}
if (rec.qname != rr->d_name && rec.qtype.getCode() != QType::NS) { // Skip NS records, as this would be a delegate that we can ignore as this does not require us to create a ENT
foundDeeper = true;
}
}

if (foundDeeper && !foundOtherWithSameName) {
Expand Down

0 comments on commit d0ce8c8

Please sign in to comment.