2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 18:19:42 +00:00

use dns_qp_getname() where possible

some calls to dns_qp_lookup() do not need partial matches, QP chains
or QP iterators. in these cases it's more efficient to use
dns_qp_getname().
This commit is contained in:
Evan Hunt 2024-04-11 10:00:22 -07:00
parent 2789e58473
commit e300dfce46
2 changed files with 21 additions and 21 deletions

View File

@ -1499,10 +1499,10 @@ find_coveringnsec(search_t *search, const dns_name_t *name,
* Lookup the predecessor in the main tree. * Lookup the predecessor in the main tree.
*/ */
node = NULL; node = NULL;
result = dns_qp_lookup(search->qpdb->tree, predecessor, NULL, NULL, result = dns_qp_getname(search->qpdb->tree, predecessor, (void **)&node,
NULL, (void **)&node, NULL); NULL);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
return (ISC_R_NOTFOUND); return (result);
} }
dns_name_copy(&node->name, fname); dns_name_copy(&node->name, fname);
@ -2793,21 +2793,16 @@ findnode(dns_db_t *db, const dns_name_t *name, bool create,
isc_rwlocktype_t tlocktype = isc_rwlocktype_none; isc_rwlocktype_t tlocktype = isc_rwlocktype_none;
TREE_RDLOCK(&qpdb->tree_lock, &tlocktype); TREE_RDLOCK(&qpdb->tree_lock, &tlocktype);
result = dns_qp_lookup(qpdb->tree, name, NULL, NULL, NULL, result = dns_qp_getname(qpdb->tree, name, (void **)&node, NULL);
(void **)&node, NULL);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
if (!create) { if (!create) {
if (result == DNS_R_PARTIALMATCH) {
result = ISC_R_NOTFOUND;
}
goto unlock; goto unlock;
} }
/* /*
* Try to upgrade the lock and if that fails unlock then relock. * Try to upgrade the lock and if that fails unlock then relock.
*/ */
TREE_FORCEUPGRADE(&qpdb->tree_lock, &tlocktype); TREE_FORCEUPGRADE(&qpdb->tree_lock, &tlocktype);
result = dns_qp_lookup(qpdb->tree, name, NULL, NULL, NULL, result = dns_qp_getname(qpdb->tree, name, (void **)&node, NULL);
(void **)&node, NULL);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
node = new_qpcnode(qpdb, name); node = new_qpcnode(qpdb, name);
result = dns_qp_insert(qpdb->tree, node, 0); result = dns_qp_insert(qpdb->tree, node, 0);

View File

@ -178,17 +178,22 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, dns_ztfind_t options,
dns_qpmulti_query(zt->multi, &qpr); dns_qpmulti_query(zt->multi, &qpr);
result = dns_qp_lookup(&qpr, name, NULL, NULL, &chain, &pval, NULL); if (exactopts == DNS_ZTFIND_EXACT) {
if (exactopts == DNS_ZTFIND_EXACT && result == DNS_R_PARTIALMATCH) { result = dns_qp_getname(&qpr, name, &pval, NULL);
result = ISC_R_NOTFOUND; } else {
} else if (exactopts == DNS_ZTFIND_NOEXACT && result == ISC_R_SUCCESS) { result = dns_qp_lookup(&qpr, name, NULL, NULL, &chain, &pval,
/* get pval from the previous chain link */ NULL);
int len = dns_qpchain_length(&chain); if (exactopts == DNS_ZTFIND_NOEXACT && result == ISC_R_SUCCESS)
if (len >= 2) { {
dns_qpchain_node(&chain, len - 2, NULL, &pval, NULL); /* get pval from the previous chain link */
result = DNS_R_PARTIALMATCH; int len = dns_qpchain_length(&chain);
} else { if (len >= 2) {
result = ISC_R_NOTFOUND; dns_qpchain_node(&chain, len - 2, NULL, &pval,
NULL);
result = DNS_R_PARTIALMATCH;
} else {
result = ISC_R_NOTFOUND;
}
} }
} }
dns_qpread_destroy(zt->multi, &qpr); dns_qpread_destroy(zt->multi, &qpr);