]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fewer name copies in previous_closest_nsec
authorAlessio Podda <alessio@isc.org>
Wed, 10 Dec 2025 09:56:48 +0000 (10:56 +0100)
committerOndřej Surý <ondrej@isc.org>
Thu, 12 Feb 2026 16:32:30 +0000 (17:32 +0100)
Part of an refactor to eliminate intermediate copies in qpzone_find.

lib/dns/qpzone.c

index b01d84b17b765e775fa08fd8ae46ca9109ec5afd..7f6cda8c3c4c25f2beb692847f862962321e4b71 100644 (file)
@@ -2916,6 +2916,8 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search,
        dns_qpmulti_query(search->qpdb->tree, &qpr);
 
        for (;;) {
+               qpznode_t *nsec_node = NULL;
+
                if (*firstp) {
                        /*
                         * This is the first attempt to find 'name' in the
@@ -2924,7 +2926,6 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search,
                        *firstp = false;
                        result = dns_qp_lookup(&qpr, name, DNS_DBNAMESPACE_NSEC,
                                               nit, NULL, NULL, NULL);
-                       qpznode_t *node = NULL;
 
                        INSIST(result != ISC_R_NOTFOUND);
                        if (result == ISC_R_SUCCESS) {
@@ -2936,11 +2937,8 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search,
                                 * NSEC record; we want the previous node
                                 * in the NSEC tree.
                                 */
-                               result = dns_qpiter_prev(nit, (void **)&node,
-                                                        NULL);
-                               if (result == ISC_R_SUCCESS) {
-                                       dns_name_copy(&node->name, name);
-                               }
+                               result = dns_qpiter_prev(
+                                       nit, (void **)&nsec_node, NULL);
                        } else if (result == DNS_R_PARTIALMATCH) {
                                /*
                                 * This was a partial match, so the
@@ -2949,10 +2947,8 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search,
                                 * what we want.
                                 */
                                isc_result_t iresult = dns_qpiter_current(
-                                       nit, (void **)&node, NULL);
-                               if (iresult == ISC_R_SUCCESS) {
-                                       dns_name_copy(&node->name, name);
-                               }
+                                       nit, (void **)&nsec_node, NULL);
+                               REQUIRE(iresult == ISC_R_SUCCESS);
                                result = ISC_R_SUCCESS;
                        }
                } else {
@@ -2963,21 +2959,20 @@ previous_closest_nsec(dns_rdatatype_t type, qpz_search_t *search,
                         * work; perhaps they lacked signature records.
                         * Keep searching.
                         */
-                       qpznode_t *tempnode = NULL;
-                       result = dns_qpiter_prev(nit, (void **)&tempnode, NULL);
-                       if (result == ISC_R_SUCCESS) {
-                               dns_name_copy(&tempnode->name, name);
-                       }
+                       result = dns_qpiter_prev(nit, (void **)&nsec_node,
+                                                NULL);
                }
+
                if (result != ISC_R_SUCCESS) {
                        break;
                }
 
                *nodep = NULL;
-               result = dns_qp_lookup(&search->qpr, name,
+               result = dns_qp_lookup(&search->qpr, &nsec_node->name,
                                       DNS_DBNAMESPACE_NORMAL, &search->iter,
                                       &search->chain, (void **)nodep, NULL);
                if (result == ISC_R_SUCCESS) {
+                       dns_name_copy(&nsec_node->name, name);
                        break;
                }