From 91de4f6490df803352d482fd1c2e164d3d487a33 Mon Sep 17 00:00:00 2001 From: Matthijs Mekking Date: Fri, 10 May 2024 17:19:15 +0200 Subject: [PATCH] Refactor fix_iterator The code below the if/else construction could only be run if the 'if' code path was taken. Move the code into the 'if' code block so that it is more easier to read. --- lib/dns/qp.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/dns/qp.c b/lib/dns/qp.c index e8ff8f66a7..3f8b0ec293 100644 --- a/lib/dns/qp.c +++ b/lib/dns/qp.c @@ -2148,6 +2148,19 @@ fix_iterator(dns_qpreader_t *qp, dns_qpiter_t *iter, dns_qpkey_t search, RUNTIME_CHECK(result == ISC_R_SUCCESS); n = iter->stack[iter->sp]; + + foundlen = leaf_qpkey(qp, n, found); + size_t nto = qpkey_compare(search, searchlen, found, + foundlen); + if (nto < to) { + /* + * We've moved to a new leaf and it differs at + * an even earlier point, so no further + * improvement is possible. + */ + return; + } + to = nto; } else { if (to <= searchlen && to <= foundlen && iter->sp > 0) { /* @@ -2187,18 +2200,6 @@ fix_iterator(dns_qpreader_t *qp, dns_qpiter_t *iter, dns_qpkey_t search, return; } - - foundlen = leaf_qpkey(qp, n, found); - size_t nto = qpkey_compare(search, searchlen, found, foundlen); - if (nto < to) { - /* - * We've moved to a new leaf and it differs at an - * even earlier point, so no further improvement is - * possible. - */ - return; - } - to = nto; } if (is_branch(n)) {