]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: ebtree: make ebmb_insert_prefix() keep a copy the new node's key
authorWilly Tarreau <w@1wt.eu>
Tue, 15 Nov 2022 07:08:31 +0000 (08:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 15 Nov 2022 08:37:09 +0000 (09:37 +0100)
Similarly to the previous patch, it's better to keep a local copy of
the new node's key instead of accessing it every time. This slightly
reduces the code's size in the descent and further improves the load
time to 7.45s.

include/import/ebmbtree.h

index fc6a5002ee69ff11a3c66b53e925423b9c886417..365042e161a2fe6e55ee05b49bbb00a3f50edd40 100644 (file)
@@ -620,6 +620,7 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l
        int old_node_bit;
        unsigned int npfx = new->node.pfx;
        unsigned int npfx1 = npfx << 1;
+       const unsigned char *nkey = new->key;
 
        side = EB_LEFT;
        troot = root->b[EB_LEFT];
@@ -679,13 +680,13 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l
                        /* No need to compare everything if the leaves are shorter than the new one. */
                        if (len > old->node.pfx)
                                len = old->node.pfx;
-                       bit = equal_bits(new->key, old->key, bit, len);
+                       bit = equal_bits(nkey, old->key, bit, len);
                        break;
                }
 
                /* WARNING: for the two blocks below, <bit> is counted in half-bits */
 
-               bit = equal_bits(new->key, old->key, bit, old_node_bit >> 1);
+               bit = equal_bits(nkey, old->key, bit, old_node_bit >> 1);
                bit = (bit << 1) + 1; // assume comparisons with normal nodes
 
                /* we must always check that our prefix is larger than the nodes
@@ -710,7 +711,7 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l
                        new->node.node_p = old->node.node_p;
                        up_ptr = &old->node.node_p;
                        new->node.bit = bit;
-                       diff = cmp_bits(new->key, old->key, bit >> 1);
+                       diff = cmp_bits(nkey, old->key, bit >> 1);
                        goto insert_above;
                }
 
@@ -746,7 +747,7 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l
                root = &old->node.branches;
                side = old_node_bit & 7;
                side ^= 7;
-               side = (new->key[old_node_bit >> 3] >> side) & 1;
+               side = (nkey[old_node_bit >> 3] >> side) & 1;
                troot = root->b[side];
        }
 
@@ -789,7 +790,7 @@ __ebmb_insert_prefix(struct eb_root *root, struct ebmb_node *new, unsigned int l
         */
        diff = 0;
        if (bit < old->node.pfx && bit < npfx)
-               diff = cmp_bits(new->key, old->key, bit);
+               diff = cmp_bits(nkey, old->key, bit);
 
        if (diff == 0) {
                /* Both keys match. Either it's a duplicate entry or we have to