From: Robin Geuze Date: Fri, 19 Mar 2021 12:56:37 +0000 (+0100) Subject: Use std::pair and an ordered_unique X-Git-Tag: dnsdist-1.6.0-rc1~28^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f41f84d098777ddf78133c0420e6a504b4e6de82;p=thirdparty%2Fpdns.git Use std::pair and an ordered_unique --- diff --git a/pdns/communicator.hh b/pdns/communicator.hh index 5ab76fc292..384ae2c669 100644 --- a/pdns/communicator.hh +++ b/pdns/communicator.hh @@ -46,31 +46,20 @@ struct SuckRequest DNSName domain; ComboAddress master; bool force; - uint8_t priority; - uint64_t sortHelper; + std::pair priorityAndOrder; bool operator<(const SuckRequest& b) const { return tie(domain, master) < tie(b.domain, b.master); } }; -struct suckQueueCmp -{ - bool operator()(const SuckRequest& a, const SuckRequest& b) const { - if (a.priority == b.priority) { - return a.sortHelper < b.sortHelper; - } - return a.priority < b.priority; - }; -}; - struct IDTag{}; struct QueueTag{}; typedef multi_index_container< SuckRequest, indexed_by< - ordered_non_unique, identity, suckQueueCmp>, + ordered_unique, member,&SuckRequest::priorityAndOrder>>, ordered_unique, identity > > > UniQueue; diff --git a/pdns/slavecommunicator.cc b/pdns/slavecommunicator.cc index 54e7511172..9197c649cd 100644 --- a/pdns/slavecommunicator.cc +++ b/pdns/slavecommunicator.cc @@ -55,8 +55,8 @@ void CommunicatorClass::addSuckRequest(const DNSName &domain, const ComboAddress sr.domain = domain; sr.master = master; sr.force = force; - sr.priority = priority; - sr.sortHelper = d_sorthelper++; + sr.priorityAndOrder.first = priority; + sr.priorityAndOrder.second = d_sorthelper++; pair res; res=d_suckdomains.insert(sr); @@ -70,10 +70,9 @@ void CommunicatorClass::addSuckRequest(const DNSName &domain, const ComboAddress // bit weird, but ok return; } - nameindex.modify(iter, [priority = priority, sorthelper = sr.sortHelper] (SuckRequest& so) { - if (priority < so.priority) { - so.priority = priority; - so.sortHelper = sorthelper; + nameindex.modify(iter, [priorityAndOrder = sr.priorityAndOrder] (SuckRequest& so) { + if (priorityAndOrder.first < so.priorityAndOrder.first) { + so.priorityAndOrder = priorityAndOrder; } }); }