]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Remove hot branch in rbtree find_node
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 6 Nov 2021 14:46:43 +0000 (10:46 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 6 Nov 2021 14:46:43 +0000 (10:46 -0400)
src/lib/util/rb.c
src/lib/util/rb.h

index 738aad1080a83e93b4221f0b5da263a85561756b..68d8c9ae9b054ad21f5c06e789ccded2a6cc1f76 100644 (file)
@@ -557,7 +557,16 @@ static inline CC_HINT(always_inline) fr_rb_node_t *find_node(fr_rb_tree_t const
 
                if (result == 0) return current;
 
-               current = (result < 0) ? current->left : current->right;
+               /*
+                *      If result > 0, return the start of the struct
+                *      i.e. the left branch.
+                *
+                *      If result < 0, return struct + sizeof(fr_rb_node_t)
+                *      i.e. the right branch.
+                *
+                *      One fewer branch in the hot loop...
+                */
+               current = *(fr_rb_node_t **)((uint8_t *)current + ((result > 0) * sizeof(fr_rb_node_t *)));
        }
 
        return NULL;
index 9c26a2ff30723ff3940a6faa10ae302d3f69c785..cfcab49945b40335e89da40df94adefcb3b837bc 100644 (file)
@@ -39,9 +39,9 @@ typedef enum {
 } fr_rb_colour_t;
 
 typedef struct fr_rb_node_s fr_rb_node_t;
-struct fr_rb_node_s {
-       fr_rb_node_t            *left;          //!< Left child
-       fr_rb_node_t            *right;         //!< Right child
+struct CC_HINT(packed) fr_rb_node_s {
+       fr_rb_node_t            *left;          //!< Left child - Must occur first in the struct.
+       fr_rb_node_t            *right;         //!< Right child - Must occur second in the struct.
        fr_rb_node_t            *parent;        //!< Parent
        void                    *data;          //!< data stored in node