2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 08:05:21 +00:00

Micro-optimizations:

- use the DNS_NAME_INIT macro in name.c
	- create dns_name_copy() and use it instead of dns_name_concatenate()
	  when doing a copy.
This commit is contained in:
Brian Wellington
2001-01-03 00:05:15 +00:00
parent 22dbaf9ad8
commit 6d5032f9a2
6 changed files with 114 additions and 56 deletions

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: query.c,v 1.163 2000/12/27 23:01:25 marka Exp $ */ /* $Id: query.c,v 1.164 2001/01/03 00:05:08 bwelling Exp $ */
#include <config.h> #include <config.h>
@@ -1378,7 +1378,7 @@ query_adda6rrset(void *arg, dns_name_t *name, dns_rdataset_t *rdataset,
goto cleanup; goto cleanup;
} }
if (dns_name_concatenate(name, NULL, fname, NULL) != ISC_R_SUCCESS) if (dns_name_copy(name, fname, NULL) != ISC_R_SUCCESS)
goto cleanup; goto cleanup;
dns_rdataset_clone(rdataset, crdataset); dns_rdataset_clone(rdataset, crdataset);
if (sigrdataset != NULL && dns_rdataset_isassociated(sigrdataset)) if (sigrdataset != NULL && dns_rdataset_isassociated(sigrdataset))
@@ -2375,7 +2375,7 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
goto cleanup; goto cleanup;
} }
tname = dns_fixedname_name(&event->foundname); tname = dns_fixedname_name(&event->foundname);
result = dns_name_concatenate(tname, NULL, fname, NULL); result = dns_name_copy(tname, fname, NULL);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
count_query(zone, is_zone, dns_statscounter_failure); count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL); QUERY_ERROR(DNS_R_SERVFAIL);
@@ -2539,8 +2539,8 @@ query_find(ns_client_t *client, dns_fetchevent_t *event) {
* dns_name_concatenate() can fail (though it shouldn't * dns_name_concatenate() can fail (though it shouldn't
* ever do so since we should have enough space). * ever do so since we should have enough space).
*/ */
result = dns_name_concatenate(client->query.qname, result = dns_name_copy(client->query.qname,
NULL, fname, NULL); fname, NULL);
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {
count_query(zone, is_zone, dns_statscounter_failure); count_query(zone, is_zone, dns_statscounter_failure);
QUERY_ERROR(DNS_R_SERVFAIL); QUERY_ERROR(DNS_R_SERVFAIL);

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: name.h,v 1.84 2000/12/29 21:54:52 bwelling Exp $ */ /* $Id: name.h,v 1.85 2001/01/03 00:05:15 bwelling Exp $ */
#ifndef DNS_NAME_H #ifndef DNS_NAME_H
#define DNS_NAME_H 1 #define DNS_NAME_H 1
@@ -1224,6 +1224,30 @@ dns_name_format(dns_name_t *name, char *cp, unsigned int size);
* Includes space for the terminating NULL. * Includes space for the terminating NULL.
*/ */
isc_result_t
dns_name_copy(dns_name_t *source, dns_name_t *dest, isc_buffer_t *target);
/*
* Makes 'dest' refer to a copy of the name in 'source'. The data are
* either copied to 'target' or the dedicated buffer in 'dest'.
*
* Requires:
* 'source' is a valid name.
*
* 'dest' is an initialized name with a dedicated buffer.
*
* 'target' is NULL or an initialized buffer.
*
* Either dest has a dedicated buffer or target != NULL.
*
* Ensures:
*
* On success, the used space in target is updated.
*
* Returns:
* ISC_R_SUCCESS
* ISC_R_NOSPACE
*/
ISC_LANG_ENDDECLS ISC_LANG_ENDDECLS
/*** /***
@@ -1238,14 +1262,6 @@ ISC_LANG_ENDDECLS
* WARNING: No assertion checking is done for these macros. * WARNING: No assertion checking is done for these macros.
*/ */
#ifdef DNS_NAME_USEINLINE
#define dns_name_init(n, o) DNS_NAME_INIT(n, o)
#define dns_name_reset(n) DNS_NAME_RESET(n)
#define dns_name_setbuffer(n, b) DNS_NAME_SETBUFFER(n, b)
#define dns_name_countlabels(n) DNS_NAME_COUNTLABELS(n)
#define dns_name_isabsolute(n) DNS_NAME_ISABSOLUTE(n)
#define DNS_NAME_INIT(n, o) \ #define DNS_NAME_INIT(n, o) \
do { \ do { \
(n)->magic = DNS_NAME_MAGIC; \ (n)->magic = DNS_NAME_MAGIC; \
@@ -1278,6 +1294,14 @@ do { \
#define DNS_NAME_COUNTLABELS(n) \ #define DNS_NAME_COUNTLABELS(n) \
((n)->labels) ((n)->labels)
#ifdef DNS_NAME_USEINLINE
#define dns_name_init(n, o) DNS_NAME_INIT(n, o)
#define dns_name_reset(n) DNS_NAME_RESET(n)
#define dns_name_setbuffer(n, b) DNS_NAME_SETBUFFER(n, b)
#define dns_name_countlabels(n) DNS_NAME_COUNTLABELS(n)
#define dns_name_isabsolute(n) DNS_NAME_ISABSOLUTE(n)
#endif /* DNS_NAME_USEINLINE */ #endif /* DNS_NAME_USEINLINE */
#endif /* DNS_NAME_H */ #endif /* DNS_NAME_H */

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: name.c,v 1.111 2000/12/29 00:59:39 bwelling Exp $ */ /* $Id: name.c,v 1.112 2001/01/03 00:05:10 bwelling Exp $ */
#include <config.h> #include <config.h>
@@ -27,9 +27,9 @@
#include <isc/string.h> #include <isc/string.h>
#include <isc/util.h> #include <isc/util.h>
#include <dns/result.h>
#include <dns/name.h>
#include <dns/compress.h> #include <dns/compress.h>
#include <dns/name.h>
#include <dns/result.h>
#define VALID_NAME(n) ISC_MAGIC_VALID(n, DNS_NAME_MAGIC) #define VALID_NAME(n) ISC_MAGIC_VALID(n, DNS_NAME_MAGIC)
@@ -308,16 +308,7 @@ dns_name_init(dns_name_t *name, unsigned char *offsets) {
/* /*
* Initialize 'name'. * Initialize 'name'.
*/ */
DNS_NAME_INIT(name, offsets);
name->magic = DNS_NAME_MAGIC;
name->ndata = NULL;
name->length = 0;
name->labels = 0;
name->attributes = 0;
name->offsets = offsets;
name->buffer = NULL;
ISC_LINK_INIT(name, link);
ISC_LIST_INIT(name->list);
} }
void void
@@ -325,9 +316,7 @@ dns_name_reset(dns_name_t *name) {
REQUIRE(VALID_NAME(name)); REQUIRE(VALID_NAME(name));
REQUIRE(BINDABLE(name)); REQUIRE(BINDABLE(name));
MAKE_EMPTY(name); DNS_NAME_RESET(name);
if (name->buffer != NULL)
isc_buffer_clear(name->buffer);
} }
void void
@@ -882,7 +871,7 @@ dns_name_matcheswildcard(const dns_name_t *name, const dns_name_t *wname) {
REQUIRE(labels > 0); REQUIRE(labels > 0);
REQUIRE(dns_name_iswildcard(wname)); REQUIRE(dns_name_iswildcard(wname));
dns_name_init(&tname, NULL); DNS_NAME_INIT(&tname, NULL);
dns_name_getlabelsequence(wname, 1, labels - 1, &tname); dns_name_getlabelsequence(wname, 1, labels - 1, &tname);
if (dns_name_fullcompare(name, &tname, &order, &nlabels, &nbits) == if (dns_name_fullcompare(name, &tname, &order, &nlabels, &nbits) ==
dns_namereln_subdomain) dns_namereln_subdomain)
@@ -2401,12 +2390,12 @@ dns_name_towire(dns_name_t *name, dns_compress_t *cctx, isc_buffer_t *target) {
* has one. * has one.
*/ */
if (name->offsets == NULL) { if (name->offsets == NULL) {
dns_name_init(&clname, clo); DNS_NAME_INIT(&clname, clo);
dns_name_clone(name, &clname); dns_name_clone(name, &clname);
name = &clname; name = &clname;
} }
dns_name_init(&gp, po); DNS_NAME_INIT(&gp, po);
dns_name_init(&gs, so); DNS_NAME_INIT(&gs, so);
offset = target->used; /*XXX*/ offset = target->used; /*XXX*/
@@ -2483,7 +2472,7 @@ dns_name_concatenate(dns_name_t *prefix, dns_name_t *suffix, dns_name_t *name,
REQUIRE(!copy_suffix); REQUIRE(!copy_suffix);
} }
if (name == NULL) { if (name == NULL) {
dns_name_init(&tmp_name, odata); DNS_NAME_INIT(&tmp_name, odata);
name = &tmp_name; name = &tmp_name;
} }
if (target == NULL && name->buffer != NULL) { if (target == NULL && name->buffer != NULL) {
@@ -3083,7 +3072,7 @@ dns_name_digest(dns_name_t *name, dns_digestfunc_t digest, void *arg) {
REQUIRE(VALID_NAME(name)); REQUIRE(VALID_NAME(name));
REQUIRE(digest != NULL); REQUIRE(digest != NULL);
dns_name_init(&downname, NULL); DNS_NAME_INIT(&downname, NULL);
isc_buffer_init(&buffer, data, sizeof(data)); isc_buffer_init(&buffer, data, sizeof(data));
result = dns_name_downcase(name, &downname, &buffer); result = dns_name_downcase(name, &downname, &buffer);
@@ -3153,3 +3142,53 @@ dns_name_format(dns_name_t *name, char *cp, unsigned int size) {
} else } else
snprintf(cp, size, "<unknown>"); snprintf(cp, size, "<unknown>");
} }
isc_result_t
dns_name_copy(dns_name_t *source, dns_name_t *dest, isc_buffer_t *target) {
unsigned char *ndata, *offsets;
dns_offsets_t odata;
/*
* Make dest a copy of source.
*/
REQUIRE(VALID_NAME(source));
REQUIRE(VALID_NAME(dest));
REQUIRE(target != NULL || dest->buffer != NULL);
if (target == NULL) {
target = dest->buffer;
isc_buffer_clear(dest->buffer);
}
REQUIRE(BINDABLE(dest));
/*
* Set up.
*/
if (target->length - target->used < source->length)
return (ISC_R_NOSPACE);
ndata = (unsigned char *)target->base + target->used;
dest->ndata = target->base;
memcpy(ndata, source->ndata, source->length);
dest->ndata = ndata;
dest->labels = source->labels;
dest->length = source->length;
if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0)
dest->attributes = DNS_NAMEATTR_ABSOLUTE;
else
dest->attributes = 0;
if (dest->labels > 0 && dest->offsets != NULL) {
INIT_OFFSETS(dest, offsets, odata);
set_offsets(dest, offsets, NULL);
}
isc_buffer_add(target, dest->length);
return (ISC_R_SUCCESS);
}

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: rbt.c,v 1.96 2000/12/11 19:24:16 bwelling Exp $ */ /* $Id: rbt.c,v 1.97 2001/01/03 00:05:11 bwelling Exp $ */
/* Principal Authors: DCL */ /* Principal Authors: DCL */
@@ -2296,8 +2296,7 @@ dns_rbtnodechain_current(dns_rbtnodechain_t *chain, dns_name_t *name,
if (chain->level_count > 0) if (chain->level_count > 0)
result = chain_name(chain, origin, ISC_FALSE); result = chain_name(chain, origin, ISC_FALSE);
else else
result = dns_name_concatenate(NULL, dns_rootname, result = dns_name_copy(dns_rootname, origin, NULL);
origin, NULL);
} }
return (result); return (result);

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: rbtdb.c,v 1.139 2000/12/07 23:37:52 marka Exp $ */ /* $Id: rbtdb.c,v 1.140 2001/01/03 00:05:12 bwelling Exp $ */
/* /*
* Principal Author: Bob Halley * Principal Author: Bob Halley
@@ -1102,8 +1102,7 @@ zone_zonecut_callback(dns_rbtnode_t *node, dns_name_t *name, void *arg) {
* is, we need to remember the node name. * is, we need to remember the node name.
*/ */
zcname = dns_fixedname_name(&search->zonecut_name); zcname = dns_fixedname_name(&search->zonecut_name);
RUNTIME_CHECK(dns_name_concatenate(name, NULL, zcname, RUNTIME_CHECK(dns_name_copy(name, zcname, NULL) ==
NULL) ==
ISC_R_SUCCESS); ISC_R_SUCCESS);
search->copy_name = ISC_TRUE; search->copy_name = ISC_TRUE;
} }
@@ -1185,7 +1184,7 @@ setup_delegation(rbtdb_search_t *search, dns_dbnode_t **nodep,
*/ */
if (foundname != NULL && search->copy_name) { if (foundname != NULL && search->copy_name) {
zcname = dns_fixedname_name(&search->zonecut_name); zcname = dns_fixedname_name(&search->zonecut_name);
result = dns_name_concatenate(zcname, NULL, foundname, NULL); result = dns_name_copy(zcname, foundname, NULL);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
} }
@@ -1622,8 +1621,7 @@ zone_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
*/ */
result = find_wildcard(&search, &node); result = find_wildcard(&search, &node);
if (result == ISC_R_SUCCESS) { if (result == ISC_R_SUCCESS) {
result = dns_name_concatenate(name, NULL, result = dns_name_copy(name, foundname, NULL);
foundname, NULL);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto tree_exit; goto tree_exit;
wild = ISC_TRUE; wild = ISC_TRUE;
@@ -2156,8 +2154,7 @@ find_deepest_zonecut(rbtdb_search_t *search, dns_rbtnode_t *node,
if (foundname != NULL) { if (foundname != NULL) {
dns_name_init(&name, NULL); dns_name_init(&name, NULL);
dns_rbt_namefromnode(node, &name); dns_rbt_namefromnode(node, &name);
result = dns_name_concatenate(&name, NULL, result = dns_name_copy(&name, foundname, NULL);
foundname, NULL);
while (result == ISC_R_SUCCESS && i > 0) { while (result == ISC_R_SUCCESS && i > 0) {
i--; i--;
level_node = search->chain.levels[i]; level_node = search->chain.levels[i];
@@ -4687,5 +4684,5 @@ dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) {
if (rbtdbiter->result != ISC_R_SUCCESS) if (rbtdbiter->result != ISC_R_SUCCESS)
return (rbtdbiter->result); return (rbtdbiter->result);
return (dns_name_concatenate(origin, NULL, name, NULL)); return (dns_name_copy(origin, name, NULL));
} }

View File

@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
/* $Id: resolver.c,v 1.191 2001/01/02 20:46:07 gson Exp $ */ /* $Id: resolver.c,v 1.192 2001/01/03 00:05:14 bwelling Exp $ */
#include <config.h> #include <config.h>
@@ -2318,7 +2318,7 @@ clone_results(fetchctx_t *fctx) {
event != NULL; event != NULL;
event = ISC_LIST_NEXT(event, ev_link)) { event = ISC_LIST_NEXT(event, ev_link)) {
name = dns_fixedname_name(&event->foundname); name = dns_fixedname_name(&event->foundname);
result = dns_name_concatenate(hname, NULL, name, NULL); result = dns_name_copy(hname, name, NULL);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
event->result = result; event->result = result;
else else
@@ -2570,8 +2570,8 @@ validated(isc_task_t *task, isc_event_t *event) {
if (hevent != NULL) { if (hevent != NULL) {
hevent->result = eresult; hevent->result = eresult;
dns_name_concatenate(vevent->name, NULL, dns_name_copy(vevent->name,
dns_fixedname_name(&hevent->foundname), NULL); dns_fixedname_name(&hevent->foundname), NULL);
dns_db_attach(fctx->res->view->cachedb, &hevent->db); dns_db_attach(fctx->res->view->cachedb, &hevent->db);
hevent->node = node; hevent->node = node;
node = NULL; node = NULL;
@@ -2641,7 +2641,7 @@ cache_name(fetchctx_t *fctx, dns_name_t *name, isc_stdtime_t now) {
if (event != NULL) { if (event != NULL) {
adbp = &event->db; adbp = &event->db;
aname = dns_fixedname_name(&event->foundname); aname = dns_fixedname_name(&event->foundname);
result = dns_name_concatenate(name, NULL, aname, NULL); result = dns_name_copy(name, aname, NULL);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
return (result); return (result);
anodep = &event->node; anodep = &event->node;
@@ -3074,7 +3074,7 @@ ncache_message(fetchctx_t *fctx, dns_rdatatype_t covers, isc_stdtime_t now) {
if (event != NULL) { if (event != NULL) {
adbp = &event->db; adbp = &event->db;
aname = dns_fixedname_name(&event->foundname); aname = dns_fixedname_name(&event->foundname);
result = dns_name_concatenate(name, NULL, aname, NULL); result = dns_name_copy(name, aname, NULL);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
goto unlock; goto unlock;
anodep = &event->node; anodep = &event->node;
@@ -3763,9 +3763,8 @@ answer_response(fetchctx_t *fctx) {
* result fits in a fixedname. * result fits in a fixedname.
*/ */
dns_fixedname_init(&fqname); dns_fixedname_init(&fqname);
result = dns_name_concatenate( result = dns_name_copy(
dns_fixedname_name(&dname), dns_fixedname_name(&dname),
NULL,
dns_fixedname_name(&fqname), dns_fixedname_name(&fqname),
NULL); NULL);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)