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;
} 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