From 104a7fb3ea964d2f9ed38df9362101b7798b3aa5 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Thu, 21 Feb 2008 15:25:22 +0000 Subject: [PATCH] couple percent shaved off in compress_tree_lookup and dname_lab_cmp. git-svn-id: file:///svn/unbound/trunk@980 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 3 +++ util/data/dname.c | 36 ++++++++++++++++++++++++++++-------- util/data/msgencode.c | 7 ++++--- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 86606487f..2b11a32f8 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,5 +1,8 @@ 21 February 2008: Wouter - speedup of root-delegation message encoding by 15%. + - minor speedup of compress tree_lookup, maybe 1%. + - speedup of dname_lab_cmp and memlowercmp - the top functions in + profiler output, maybe a couple percent when it matters. 20 February 2008: Wouter - setup speec_cache for need-ldns-testns in dotests. diff --git a/util/data/dname.c b/util/data/dname.c index 1b7fa2950..a4d92688b 100644 --- a/util/data/dname.c +++ b/util/data/dname.c @@ -420,7 +420,6 @@ memlowercmp(uint8_t* p1, uint8_t* p2, uint8_t len) return 0; } - int dname_lab_cmp(uint8_t* d1, int labs1, uint8_t* d2, int labs2, int* mlabs) { @@ -428,7 +427,6 @@ dname_lab_cmp(uint8_t* d1, int labs1, uint8_t* d2, int labs2, int* mlabs) int atlabel = labs1; int lastmlabs; int lastdiff = 0; - int c; /* first skip so that we compare same label. */ if(labs1 > labs2) { while(atlabel > labs2) { @@ -460,13 +458,35 @@ dname_lab_cmp(uint8_t* d1, int labs1, uint8_t* d2, int labs2, int* mlabs) lastdiff = -1; else lastdiff = 1; lastmlabs = atlabel; - } else if((c=memlowercmp(d1, d2, len1)) != 0) { - lastdiff = c; - lastmlabs = atlabel; + d1 += len1; + d2 += len2; + } else { + /* memlowercmp is inlined here; or just like + * if((c=memlowercmp(d1, d2, len1)) != 0) { + * lastdiff = c; + * lastmlabs = atlabel; } apart from d1++,d2++ */ + while(len1) { + if(*d1 != *d2 && tolower((int)*d1) + != tolower((int)*d2)) { + if(tolower((int)*d1) < + tolower((int)*d2)) { + lastdiff = -1; + lastmlabs = atlabel; + d1 += len1; + d2 += len1; + break; + } + lastdiff = 1; + lastmlabs = atlabel; + d1 += len1; + d2 += len1; + break; /* out of memlowercmp */ + } + d1++; + d2++; + len1--; + } } - - d1 += len1; - d2 += len2; atlabel--; } /* last difference atlabel number, so number of labels matching, diff --git a/util/data/msgencode.c b/util/data/msgencode.c index 016cfc089..cad5b7e7f 100644 --- a/util/data/msgencode.c +++ b/util/data/msgencode.c @@ -104,7 +104,7 @@ compress_tree_search(struct compress_tree_node** tree, uint8_t* dname, int c, n, closen=0; struct compress_tree_node* p = *tree; struct compress_tree_node* close = 0; - *insertpt = tree; + struct compress_tree_node** prev = tree; while(p) { if((c = dname_lab_cmp(dname, labs, p->dname, p->labs, &n)) == 0) { @@ -113,15 +113,16 @@ compress_tree_search(struct compress_tree_node** tree, uint8_t* dname, return 1; } if(c<0) { - *insertpt = &p->left; + prev = &p->left; p = p->left; } else { closen = n; close = p; /* p->dname is smaller than dname */ - *insertpt = &p->right; + prev = &p->right; p = p->right; } } + *insertpt = prev; *matchlabels = closen; *match = close; return 0; -- 2.47.2