]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use twice as fewer dns_tolower() calls in pdns_ilexicographical_compare().
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 25 Jun 2025 17:07:07 +0000 (19:07 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 25 Jun 2025 17:07:07 +0000 (19:07 +0200)
[Although the compiler had probably been smart enough to optimize this
already]

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/misc.hh

index 0b2d0883833edec5fd1c77c17bdec0951b6505f2..710adaa9094e3c518c7012ea46d19bfd4cea7470 100644 (file)
@@ -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++;
   }