From: Miod Vallat Date: Wed, 25 Jun 2025 17:17:21 +0000 (+0200) Subject: Factor out triplicated comparison code. X-Git-Tag: rec-5.3.0-alpha2~40^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac9e218c8ea6a00c5395a27d8279f69d7a5ef294;p=thirdparty%2Fpdns.git Factor out triplicated comparison code. Signed-off-by: Miod Vallat --- diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index f9042b590a..07ed9e59f7 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -62,6 +62,14 @@ inline unsigned char dns_tolower(unsigned char chr) #include "burtle.hh" #include "views.hh" +struct DNSNameCompare +{ + bool operator()(const unsigned char& lhs, const unsigned char& rhs) const + { + return dns_tolower(lhs) < dns_tolower(rhs); + } +}; + /* Quest in life: accept escaped ascii presentations of DNS names and store them "natively" accept a DNS packet with an offset, and extract a DNS name from it @@ -175,11 +183,10 @@ public: bool operator<(const DNSName& rhs) const // this delivers _some_ kind of ordering, but not one useful in a DNS context. Really fast though. { + // note that this is case insensitive, including on the label lengths return std::lexicographical_compare(d_storage.rbegin(), d_storage.rend(), rhs.d_storage.rbegin(), rhs.d_storage.rend(), - [](const unsigned char& a, const unsigned char& b) { - return dns_tolower(a) < dns_tolower(b); - }); // note that this is case insensitive, including on the label lengths + DNSNameCompare()); } inline bool canonCompare(const DNSName& rhs) const; @@ -281,9 +288,7 @@ inline bool DNSName::canonCompare(const DNSName& rhs) const d_storage.c_str() + ourpos[ourcount] + 1 + *(d_storage.c_str() + ourpos[ourcount]), rhs.d_storage.c_str() + rhspos[rhscount] + 1, rhs.d_storage.c_str() + rhspos[rhscount] + 1 + *(rhs.d_storage.c_str() + rhspos[rhscount]), - [](const unsigned char& a, const unsigned char& b) { - return dns_tolower(a) < dns_tolower(b); - }); + DNSNameCompare()); // cout<<"Forward: "<