rattrs: Reverted attempt at merged mtree split commits

See previous commit for why.

The merged commits surprisingly cost more than separate commit
functions. I guess because the compiler is smart enough to deduplicate
the two logic paths here:

                 code          stack          ctx
  before:       35324           2176          660
  after:        35316 (-0.0%)   2176 (+0.0%)  660 (+0.0%)

                 code          stack          ctx
  gbmap before: 38172           2192          772
  gbmap after:  38168 (-0.0%)   2192 (+0.0%)  772 (+0.0%)

The good news is this is a win for readability, I think the separate
conditions are easier to understand than a merged commit muddied with a
bunch of lfs3->mtree.r.weight == 0 checks.
This commit is contained in:
Christopher Haster
2025-12-01 15:17:28 -06:00
parent 90ba24787f
commit e29cc23acd
+33 -20
View File
@@ -9143,19 +9143,11 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
// new mtree?
if (lfs3->mtree.r.weight == 0) {
lfs3_btree_init(&mtree_);
}
// update our mtree
err = lfs3_mtree_commit(lfs3, &mtree_,
(lfs3->mtree.r.weight == 0)
? 0
: lfs3_mbid(lfs3, mdir->mid),
LFS3_RATTRS(
0, LFS3_RATTRS(
LFS3_RATTR(3, LFS3_TAG_MDIR, -2, LFS3_FROM_MPTR),
LFS3_RATTR_WEIGHT(
(lfs3->mtree.r.weight == 0)
? +(1 << lfs3->mbits)
: 0),
LFS3_RATTR_WEIGHT(+(1 << lfs3->mbits)),
LFS3_RATTR_ARG(mdir_[0].r.blocks),
LFS3_RATTR(3, LFS3_TAG_MNAME, -2, LFS3_FROM_CAT, 1),
LFS3_RATTR_WEIGHT(+(1 << lfs3->mbits)),
@@ -9167,6 +9159,23 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
goto failed;
}
// update our mtree
} else {
err = lfs3_mtree_commit(lfs3, &mtree_,
lfs3_mbid(lfs3, mdir->mid), LFS3_RATTRS(
LFS3_RATTR(2, LFS3_TAG_MDIR, 0, LFS3_FROM_MPTR),
LFS3_RATTR_ARG(mdir_[0].r.blocks),
LFS3_RATTR(3, LFS3_TAG_MNAME, -2, LFS3_FROM_CAT, 1),
LFS3_RATTR_WEIGHT(+(1 << lfs3->mbits)),
LFS3_RATTR_ARG(&split_name),
LFS3_RATTR(2, LFS3_TAG_MDIR, 0, LFS3_FROM_MPTR),
LFS3_RATTR_ARG(mdir_[1].r.blocks),
LFS3_RATTR_NULL));
if (err) {
goto failed;
}
}
// need to drop?
} else if (err == LFS3_ERR_NOENT) {
LFS3_INFO("Dropping mdir %"PRId32" 0x{%"PRIx32",%"PRIx32"}",
@@ -9210,24 +9219,28 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir,
// new mtree?
if (lfs3->mtree.r.weight == 0) {
lfs3_btree_init(&mtree_);
}
// update our mtree
err = lfs3_mtree_commit(lfs3, &mtree_,
(lfs3->mtree.r.weight == 0)
? 0
: lfs3_mbid(lfs3, mdir->mid),
LFS3_RATTRS(
0, LFS3_RATTRS(
LFS3_RATTR(3, LFS3_TAG_MDIR, -2, LFS3_FROM_MPTR),
LFS3_RATTR_WEIGHT(
(lfs3->mtree.r.weight == 0)
? +(1 << lfs3->mbits)
: 0),
LFS3_RATTR_WEIGHT(+(1 << lfs3->mbits)),
LFS3_RATTR_ARG(mdir_[0].r.blocks),
LFS3_RATTR_NULL));
if (err) {
goto failed;
}
// update our mtree
} else {
err = lfs3_mtree_commit(lfs3, &mtree_,
lfs3_mbid(lfs3, mdir->mid), LFS3_RATTRS(
LFS3_RATTR(2, LFS3_TAG_MDIR, 0, LFS3_FROM_MPTR),
LFS3_RATTR_ARG(mdir_[0].r.blocks),
LFS3_RATTR_NULL));
if (err) {
goto failed;
}
}
}
// patch any pending grms