From 6493dfc057f575588d121c87e6dea65a7319e897 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 1 Jul 2019 14:57:47 +0200 Subject: [PATCH] rec: Small speed improvements in the SyncRes --- pdns/syncres.cc | 12 ++++++++---- pdns/syncres.hh | 12 ++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index a9d40cab8..2750b4d62 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -999,19 +999,19 @@ void SyncRes::getBestNSFromCache(const DNSName &qname, const QType& qtype, vecto } } - if(beenthere.count(answer)) { + auto insertionPair = beenthere.insert(std::move(answer)); + if(!insertionPair.second) { brokeloop=true; LOG(prefix<::const_iterator j=beenthere.begin();j!=beenthere.end();++j) { - bool neo = !(*j< answer || answer<*j); + bool neo = (j == insertionPair.first); LOG(prefix<qname<<"|"<qtype)<<" ("<<(unsigned int)j->bestns.size()<<")"<empty()) { + return t_sstorage.domainmap->end(); + } + SyncRes::domainmap_t::const_iterator ret; do { ret=t_sstorage.domainmap->find(*qname); @@ -1045,7 +1049,6 @@ SyncRes::domainmap_t::const_iterator SyncRes::getBestAuthZone(DNSName* qname) co /** doesn't actually do the work, leaves that to getBestNSFromCache */ DNSName SyncRes::getBestNSNamesFromCache(const DNSName &qname, const QType& qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set&beenthere) { - DNSName subdomain(qname); DNSName authdomain(qname); domainmap_t::const_iterator iter=getBestAuthZone(&authdomain); @@ -1063,6 +1066,7 @@ DNSName SyncRes::getBestNSNamesFromCache(const DNSName &qname, const QType& qtyp return authdomain; } + DNSName subdomain(qname); vector bestns; getBestNSFromCache(subdomain, qtype, bestns, flawedNSSet, depth, beenthere); diff --git a/pdns/syncres.hh b/pdns/syncres.hh index d0edf346d..bbe35beef 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -67,7 +67,7 @@ extern GlobalStateHolder g_dontThrottleNetmasks; class RecursorLua4; -typedef map< +typedef std::unordered_map< DNSName, pair< vector, @@ -337,7 +337,7 @@ public: ComboAddress d_best; }; - typedef map nsspeeds_t; + typedef std::unordered_map nsspeeds_t; typedef map ednsstatus_t; vState getDSRecords(const DNSName& zone, dsmap_t& ds, bool onlyTA, unsigned int depth, bool bogusOnNXD=true, bool* foundCut=nullptr); @@ -385,7 +385,7 @@ public: void addSOA(std::vector& records) const; }; - typedef map domainmap_t; + typedef std::unordered_map domainmap_t; typedef Throttle > throttle_t; typedef Counters fails_t; @@ -781,11 +781,11 @@ private: { DNSName qname; set > bestns; - uint8_t qtype; // only A and AAAA anyhow + uint8_t qtype; bool operator<(const GetBestNSAnswer &b) const { - return boost::tie(qname, qtype, bestns) < - boost::tie(b.qname, b.qtype, b.bestns); + return boost::tie(qtype, qname, bestns) < + boost::tie(b.qtype, b.qname, b.bestns); } }; -- 2.40.0