]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
couple percent shaved off in compress_tree_lookup and dname_lab_cmp.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 21 Feb 2008 15:25:22 +0000 (15:25 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Thu, 21 Feb 2008 15:25:22 +0000 (15:25 +0000)
git-svn-id: file:///svn/unbound/trunk@980 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
util/data/dname.c
util/data/msgencode.c

index 86606487f425776939417131268e57077ec1998a..2b11a32f8982eae9b5007855fcbfb2d0a0aaa337 100644 (file)
@@ -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.
index 1b7fa2950fbf737147e5e90eea351eac676902c9..a4d92688b210ee4d0e78847c43a1afc2e6309c43 100644 (file)
@@ -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,
index 016cfc089439fc5b36b05de292f5f8a1b7706167..cad5b7e7fbf2dad8abcf5a5e303ccd528cd362c6 100644 (file)
@@ -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;