]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
iputils: Return early when the tree is empty
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 22 May 2026 13:08:09 +0000 (15:08 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 22 May 2026 13:08:09 +0000 (15:08 +0200)
This brings a small speed-up when the proxy protocol ACL is empty,
for example.

Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/iputils.hh

index 4a00906553272d77db18742a9afff96f289aec1d..6a00d04c8caa02aa149c2672085e5968a4d23d21 100644 (file)
@@ -1511,6 +1511,9 @@ public:
   //<! Returns "best match" for key_type, which might not be value
   [[nodiscard]] node_type* lookup(const key_type& value) const
   {
+    if (empty()) {
+      return nullptr;
+    }
     uint8_t max_bits = value.getBits();
     return lookupImpl(value, max_bits);
   }
@@ -1518,6 +1521,9 @@ public:
   //<! Perform best match lookup for value, using at most max_bits
   [[nodiscard]] node_type* lookup(const ComboAddress& value, int max_bits = 128) const
   {
+    if (empty()) {
+      return nullptr;
+    }
     uint8_t addr_bits = value.getBits();
     if (max_bits < 0 || max_bits > addr_bits) {
       max_bits = addr_bits;