From: Arran Cudbard-Bell Date: Sat, 6 Nov 2021 14:46:43 +0000 (-0400) Subject: Remove hot branch in rbtree find_node X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b19a7ac6737e7a0f0aefb20cd94d9441d0e0eb3c;p=thirdparty%2Ffreeradius-server.git Remove hot branch in rbtree find_node --- diff --git a/src/lib/util/rb.c b/src/lib/util/rb.c index 738aad1080a..68d8c9ae9b0 100644 --- a/src/lib/util/rb.c +++ b/src/lib/util/rb.c @@ -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; diff --git a/src/lib/util/rb.h b/src/lib/util/rb.h index 9c26a2ff307..cfcab49945b 100644 --- a/src/lib/util/rb.h +++ b/src/lib/util/rb.h @@ -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