HomeFreeBSD

rb_tree: speed-up double rotation

Description

rb_tree: speed-up double rotation

RB_ROTATE_LEFT (and it symmetric twin) modify the rb-tree, adjusting
pointers so that what started as a proper tree ends up a proper
tree. When two consecutive rotations move the same node up the tree,
some of the pointers changed in the first rotation are immediately
changed again in the second - namely, the pointer from the rising node
to its new parent, and the pointer from that parent back to the rising
node. This change removes from RB_ROTATE macros the responsibility for
managing those two pointers, and leaves it to the code that calls for
rotations to fix up those pointers afterward. That drops a comparison
and a pair of assignments from every INSERT_COLOR or REMOVE_COLOR call
that ends in a double rotation.

A side-effect of this change is that the SWAP_CHILD macro must take as
a parameter a pointer to the node that is changing children, where it
is now computed from the old child. Since this macro is called in a
couple of places besides the RB_ROTATE macros, those calls are also
affected.

Reviewed by: alc
MFC after: 3 weeks
Differential Revision: https://reviews.freebsd.org/D36266

(cherry picked from commit 02d0c43c9e53b3055b17719a184a813032040f79)

Details

Provenance
dougmAuthored on Aug 19 2022, 11:11 PM
Reviewer
alc
Differential Revision
D36266: rb_tree: avoid double-writing in double rotation
Parents
rG2a92854d81a1: libc/stdio: only roll FILE state back on EINTR
Branches
Unknown
Tags
Unknown