From 7fc9cbe8051eb5574e9f19446ae1c6897c6a89ff Mon Sep 17 00:00:00 2001 From: bert hubert Date: Fri, 19 Feb 2016 21:28:05 +0100 Subject: [PATCH] turns out we were using libc tolower in performance sensitive places.. top in perf --- pdns/dnsname.cc | 2 +- pdns/dnsname.hh | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index c2c9a710f..ddc3998c0 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -284,7 +284,7 @@ bool DNSName::operator==(const DNSName& rhs) const auto us = d_storage.crbegin(); auto p = rhs.d_storage.crbegin(); for(; us != d_storage.crend() && p != rhs.d_storage.crend(); ++us, ++p) { // why does this go backward? - if(tolower(*p) != tolower(*us)) + if(dns2_tolower(*p) != dns2_tolower(*us)) return false; } return true; diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 6e7e744ac..7c9326e08 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -26,6 +26,12 @@ uint32_t burtleCI(const unsigned char* k, uint32_t lengh, uint32_t init); NOTE: For now, everything MUST be . terminated, otherwise it is an error */ +inline char dns2_tolower(char c) +{ + if(c>='A' && c<='Z') + c+='a'-'A'; + return c; +} class DNSName { @@ -83,7 +89,7 @@ public: return std::lexicographical_compare(d_storage.rbegin(), d_storage.rend(), rhs.d_storage.rbegin(), rhs.d_storage.rend(), [](const char& a, const char& b) { - return tolower(a) < tolower(b); + return dns2_tolower(a) < dns2_tolower(b); }); // note that this is case insensitive, including on the label lengths } @@ -102,13 +108,6 @@ private: size_t hash_value(DNSName const& d); -inline char dns2_tolower(char c) -{ - if(c>='A' && c<='Z') - c+='a'-'A'; - return c; -} - inline bool DNSName::canonCompare(const DNSName& rhs) const { -- 2.49.0