Skip to content

Commit 2fbf90f

Browse files
committed
iputils: Return early when the tree is empty
This brings a small speed-up when the proxy protocol ACL is empty, for example. Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
1 parent 93ff5fb commit 2fbf90f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

pdns/iputils.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,13 +1511,19 @@ public:
15111511
//<! Returns "best match" for key_type, which might not be value
15121512
[[nodiscard]] node_type* lookup(const key_type& value) const
15131513
{
1514+
if (empty()) {
1515+
return nullptr;
1516+
}
15141517
uint8_t max_bits = value.getBits();
15151518
return lookupImpl(value, max_bits);
15161519
}
15171520

15181521
//<! Perform best match lookup for value, using at most max_bits
15191522
[[nodiscard]] node_type* lookup(const ComboAddress& value, int max_bits = 128) const
15201523
{
1524+
if (empty()) {
1525+
return nullptr;
1526+
}
15211527
uint8_t addr_bits = value.getBits();
15221528
if (max_bits < 0 || max_bits > addr_bits) {
15231529
max_bits = addr_bits;

0 commit comments

Comments
 (0)