From 70b4889c85f58f683047f2bfbf46b33e01c3b23a Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Mon, 22 Jan 2001 20:41:43 +0000 Subject: [PATCH] A minor optimation to the rbt hash code that should reduce the number of calls to dns_name_fullcompare(). --- lib/dns/rbt.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index 7c97732cbb..5f7d831efd 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: rbt.c,v 1.98 2001/01/09 21:51:13 bwelling Exp $ */ +/* $Id: rbt.c,v 1.99 2001/01/22 20:41:43 bwelling Exp $ */ /* Principal Authors: DCL */ @@ -897,7 +897,25 @@ dns_rbt_findnode(dns_rbt_t *rbt, dns_name_t *name, dns_name_t *foundname, if (hnode != NULL) { current = hnode; - continue; + /* + * This is an optimization. If hashing found + * the right node, the next call to + * dns_name_fullcompare() would obviously + * return _equal or _subdomain. Determine + * which of those would be the case by + * checking if the full name was hashed. Then + * make it look like dns_name_fullcompare + * was called and jump to the right place. + */ + if (tlabels == nlabels) { + compared = dns_namereln_equal; + break; + } else { + common_labels = 1; + common_bits = 0; + compared = dns_namereln_subdomain; + goto subdomain; + } } if (tlabels++ < nlabels) @@ -942,6 +960,7 @@ dns_rbt_findnode(dns_rbt_t *rbt, dns_name_t *name, dns_name_t *foundname, * down pointer and search in the new tree. */ if (compared == dns_namereln_subdomain) { + subdomain: /* * Whack off the current node's common parts * for the name to search in the next level.