if (!ret.empty()) {
#ifdef notyet
+ // As dedupping is relatively expensive do not dedup in general. We do have a few cases
+ // where we call dedup explicitly, e.g. when doing NAT64 or when adding NSEC records in
+ // doCNAMECacheCheck
pdns::dedupRecords(ret);
#endif
pdns::orderAndShuffle(ret, false);
lwr.d_records = std::move(vec);
}
#ifdef notyet
+ // As dedupping is relatively expensive and having dup records not really hurts as far as we have seen, do not dedup.
if (auto count = pdns::dedupRecords(lwr.d_records); count > 0) {
LOG(prefix << qname << ": Removed " << count << " duplicate records from response received from " << auth << endl);
}
unsigned int pdns::dedupRecords(vector<DNSRecord>& rrs)
{
- // This function tries to avoid unneccesary work
+ // This function tries to avoid unnecessary work
// First a vector with zero or one element does not need dedupping
if (rrs.size() <= 1) {
return 0;
}
// We avoid calling erase, as it calls a lot of move constructors. This can hurt, especially if
- // you call it on a large vector muliple times.
+ // you call it on a large vector multiple times.
// So we just take the elements that are unique
std::vector<DNSRecord> ret;
ret.reserve(rrs.size() - numDups);
{
explicit DedupRecordsTest(size_t howmany, bool dedup, bool withdup = false) : d_howmany(howmany), d_dedup(dedup), d_withdup(withdup)
{
- }
-
- [[nodiscard]] string getName() const
- {
- return std::to_string(d_howmany) + " DedupRecords" + std::string(d_dedup ? "" : " (generate only)") +
- std::string(d_withdup ? " (with dup)" : "");
- }
-
- void operator()() const
- {
- std::vector<DNSRecord> vec;
- vec.reserve(d_howmany);
+ d_vec.reserve(d_howmany);
std::string name("some.name.in.some.domain");
auto count = d_howmany;
if (d_withdup) {
auto content = DNSRecordContent::make(QType::TXT, QClass::IN, "\"a text " + std::to_string(i) + "\"");
DNSRecord rec(name, content, QType::TXT);
if (i == 0 && d_withdup) {
- vec.emplace_back(rec);
+ d_vec.emplace_back(rec);
}
- vec.emplace_back(std::move(rec));
+ d_vec.emplace_back(std::move(rec));
}
+ }
+
+ [[nodiscard]] string getName() const
+ {
+ return std::to_string(d_howmany) + " DedupRecords" + std::string(d_dedup ? "" : " (setup only)") +
+ std::string(d_withdup ? " (with dup)" : "");
+ }
+ void operator()() const
+ {
+ auto vec{d_vec};
if (d_dedup) {
pdns::dedupRecords(vec);
}
}
private:
+ vector<DNSRecord> d_vec;
size_t d_howmany;
bool d_dedup;
bool d_withdup;