Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 1975e593 authored by David Woodhouse's avatar David Woodhouse
Browse files

[RBTREE] Remove dead code in rb_erase()



Observe rb_erase(), when the victim node 'old' has two children so
neither of the simple cases at the beginning are taken.

Observe that it effectively does an 'rb_next()' operation to find the
next (by value) node in the tree. That is; we go to the victim's
right-hand child and then follow left-hand pointers all the way
down the tree as far as we can until we find the next node 'node'. We
end up with 'node' being either the same immediate right-hand child of
'old', or one of its descendants on the far left-hand side.

For a start, we _know_ that 'node' has a parent. We can drop that check.

We also know that if 'node's parent is 'old', then 'node' is the
right-hand child of its parent. And that if 'node's parent is _not_
'old', then 'node' is the left-hand child of its parent.

So instead of checking for 'node->rb_parent == old' in one place and
also checking 'node's heritage separately when we're trying to change
its link from its parent, we can shuffle things around a bit and do
it like this...

Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent 21f1d5fc
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment