btree: Tweaked btree root conditions in lfs3_btree_commit_
The child rbyd inherits all of the btree's root state when we hit the
root, including the shrub bit. This means we don't need to check
child.block == btree.block, since only the btree root can be shrubbed
(how would non-root shrubs even work? wait... they could work, but I
think it would just end up a worse balanced binary tree? anyways).
This lets us reorder things into the rare 3-case if statement, which
helps a bit with readability:
- !lfs3_rbyd_trunk(&child) || lfs3_rbyd_isshrub(&child) => need root
- child.blocks[0] == btree->blocks[0] => is root
- otherwise => not root
Shaved off some code:
code stack ctx
before: 36832 2368 656
after: 36828 (-0.0%) 2368 (+0.0%) 656 (+0.0%)
This commit is contained in:
@@ -5525,24 +5525,22 @@ static int lfs3_btree_commit_(lfs3_t *lfs3,
|
|||||||
// we will always need our parent, so go ahead and find it
|
// we will always need our parent, so go ahead and find it
|
||||||
lfs3_rbyd_t parent = {.trunk=0, .weight=0};
|
lfs3_rbyd_t parent = {.trunk=0, .weight=0};
|
||||||
lfs3_srid_t pid = 0;
|
lfs3_srid_t pid = 0;
|
||||||
// are we root?
|
// new root? shrub root? yield the final root commit to
|
||||||
if (!lfs3_rbyd_trunk(&child)
|
// higher-level btree/bshrub logic
|
||||||
|| child.blocks[0] == btree->blocks[0]) {
|
if (!lfs3_rbyd_trunk(&child) || lfs3_rbyd_isshrub(&child)) {
|
||||||
// new root? shrub root? yield the final root commit to
|
bcommit->bid = rid;
|
||||||
// higher-level btree/bshrub logic
|
return (!lfs3_rbyd_trunk(&child))
|
||||||
if (!lfs3_rbyd_trunk(&child)
|
? LFS3_ERR_RANGE
|
||||||
|| lfs3_rbyd_isshrub(btree)) {
|
: LFS3_ERR_EXIST;
|
||||||
bcommit->bid = rid;
|
|
||||||
return (!lfs3_rbyd_trunk(&child))
|
|
||||||
? LFS3_ERR_RANGE
|
|
||||||
: LFS3_ERR_EXIST;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// are we root?
|
||||||
|
} else if (child.blocks[0] == btree->blocks[0]) {
|
||||||
// mark btree as unerased in case of failure, our btree rbyd and
|
// mark btree as unerased in case of failure, our btree rbyd and
|
||||||
// root rbyd can diverge if there's a split, but we would have
|
// root rbyd can diverge if there's a split, but we would have
|
||||||
// marked the old root as unerased earlier anyways
|
// marked the old root as unerased earlier anyways
|
||||||
lfs3_btree_claim(btree);
|
lfs3_btree_claim(btree);
|
||||||
|
|
||||||
|
// need to lookup child's parent
|
||||||
} else {
|
} else {
|
||||||
int err = lfs3_btree_parent(lfs3, btree, bcommit->bid, &child,
|
int err = lfs3_btree_parent(lfs3, btree, bcommit->bid, &child,
|
||||||
&parent, &pid);
|
&parent, &pid);
|
||||||
|
|||||||
Reference in New Issue
Block a user