From 69bc7acda72bc6bf93dcb66ca7b2d960f72fdc8c Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Wed, 25 Jun 2025 19:07:07 +0200 Subject: [PATCH] Use twice as fewer dns_tolower() calls in pdns_ilexicographical_compare(). [Although the compiler had probably been smart enough to optimize this already] Signed-off-by: Miod Vallat --- pdns/misc.hh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pdns/misc.hh b/pdns/misc.hh index 0b2d088383..710adaa909 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -385,8 +385,11 @@ inline bool pdns_ilexicographical_compare(const std::string& a, const std::strin const unsigned char *aPtr = (const unsigned char*)a.c_str(), *bPtr = (const unsigned char*)b.c_str(); const unsigned char *aEptr = aPtr + a.length(), *bEptr = bPtr + b.length(); while(aPtr != aEptr && bPtr != bEptr) { - if ((*aPtr != *bPtr) && (dns_tolower(*aPtr) - dns_tolower(*bPtr))) - return (dns_tolower(*aPtr) - dns_tolower(*bPtr)) < 0; + if (*aPtr != *bPtr) { + if (int rc = dns_tolower(*aPtr) - dns_tolower(*bPtr); rc != 0) { + return rc < 0; + } + } aPtr++; bPtr++; } -- 2.47.2