Return node pointer in step

Part of an refactor to eliminate intermediate copies in qpzone_find.
This commit is contained in:
Alessio Podda 2025-12-22 14:43:40 +01:00 committed by Ondřej Surý
parent 33dfd3c0ce
commit 169cbe8431
No known key found for this signature in database
GPG key ID: 2820F37E873DEA41

View file

@ -2641,7 +2641,9 @@ typedef enum { FORWARD, BACK } direction_t;
*/
static bool
step(qpz_search_t *search, dns_qpiter_t *it, direction_t direction,
dns_name_t *nextname) {
qpznode_t **node_p) {
REQUIRE(node_p != NULL && *node_p == NULL);
qpznode_t *node = NULL, *previous_node = NULL;
isc_result_t result = ISC_R_SUCCESS;
@ -2671,7 +2673,7 @@ step(qpz_search_t *search, dns_qpiter_t *it, direction_t direction,
if (result == ISC_R_SUCCESS) {
if (previous_node != NULL) {
dns_name_copy(&previous_node->name, nextname);
*node_p = previous_node;
}
return true;
}
@ -2681,8 +2683,7 @@ step(qpz_search_t *search, dns_qpiter_t *it, direction_t direction,
static bool
activeempty(qpz_search_t *search, dns_qpiter_t *it, const dns_name_t *current) {
dns_fixedname_t fnext;
dns_name_t *next = dns_fixedname_initname(&fnext);
qpznode_t *next_node = NULL;
/*
* The iterator is currently pointed at the predecessor
@ -2697,17 +2698,15 @@ activeempty(qpz_search_t *search, dns_qpiter_t *it, const dns_name_t *current) {
/* An ENT at the end of the zone is impossible */
return false;
}
return step(search, it, FORWARD, next) &&
dns_name_issubdomain(next, current);
return step(search, it, FORWARD, &next_node) &&
dns_name_issubdomain(&next_node->name, current);
}
static bool
wildcard_blocked(qpz_search_t *search, const dns_name_t *qname,
dns_name_t *wname) {
isc_result_t result;
dns_fixedname_t fnext;
dns_fixedname_t fprev;
dns_name_t *next = NULL, *prev = NULL;
qpznode_t *next_node = NULL, *prev_node = NULL;
dns_name_t name;
dns_name_t rname;
dns_name_t tname;
@ -2719,8 +2718,6 @@ wildcard_blocked(qpz_search_t *search, const dns_name_t *qname,
dns_name_init(&name);
dns_name_init(&tname);
dns_name_init(&rname);
next = dns_fixedname_initname(&fnext);
prev = dns_fixedname_initname(&fprev);
/*
* The qname seems to have matched a wildcard, but we
@ -2734,13 +2731,13 @@ wildcard_blocked(qpz_search_t *search, const dns_name_t *qname,
* data.
*/
it = search->iter;
check_prev = step(search, &it, BACK, prev);
check_prev = step(search, &it, BACK, &prev_node);
/* Now reset the iterator and look for a successor with data. */
it = search->iter;
result = dns_qpiter_next(&it, NULL, NULL);
if (result == ISC_R_SUCCESS) {
check_next = step(search, &it, FORWARD, next);
check_next = step(search, &it, FORWARD, &next_node);
}
if (!check_prev && !check_next) {
@ -2757,8 +2754,10 @@ wildcard_blocked(qpz_search_t *search, const dns_name_t *qname,
dns_name_getlabelsequence(wname, 1, n - 1, &tname);
do {
if ((check_prev && dns_name_issubdomain(prev, &rname)) ||
(check_next && dns_name_issubdomain(next, &rname)))
if ((check_prev &&
dns_name_issubdomain(&prev_node->name, &rname)) ||
(check_next &&
dns_name_issubdomain(&next_node->name, &rname)))
{
return true;
}