Reworked lfsr_bshrub_t, renamed file.o -> file.b

This moves all of the shrub tracking logic from lfsr_obshrub_t into
lfsr_bshrub_t, completely drops the lfsr_obshrub_t type, and changes all
lfsr_bshrub_* functions to take lfsr_bshrub_t instead of the mdir+shrub
pair.

This makes the lfsr_bshrub_* functions <-> lfsr_bshrub_t relationship
more consistent with other APIs, such as lfsr_btree_t:

  - lfsr_bshrub_lookupnext(lfs, &file->o.o.mdir, &file->o.bshrub, ...)
  + lfsr_bshrub_lookupnext(lfs, &file->b, ...)

I think the reason why this design wasn't obvious before is because, at
least conceptually, having the lfsr_mdir_t live inside the lfsr_bshrub_t
is a bit weird. It's only thanks to lfsr_file_t invasively using the
internal lfsr_mdir_t that we can avoid duplicate lfsr_mdir_t objects.

This also reorganizes the structs in lfs.h a bit, and renames the
related file.o -> file.b fields (much needed because lfs->gc.t.o.o.mdir.
rbyd.blocks was starting to get _real_ confusing).

---

Unfortunately, reducing the number of arguments to lfsr_bshrub_*
functions did not save nearly as much code as I thought it would. It
even ended up with a net _increase_ of code, apparently due to needing
to recalculate the bshrub->shrub offset more often:

           code          stack          ctx
  before: 36476           2608          640
  after:  36484 (+0.0%)   2608 (+0.0%)  640 (+0.0%)

Strange, but this rework is still worthwhile if only for the code
readability.
This commit is contained in:
Christopher Haster
2025-02-03 03:07:30 -06:00
parent fd62ef9674
commit bc639b03f2
7 changed files with 487 additions and 506 deletions
+12 -12
View File
@@ -977,7 +977,7 @@ code = '''
lfsr_file_sync(&lfs, &file) => 0;
// delete any bshrub/btree
lfsr_mdir_commit(&lfs, &file.o.o.mdir, LFSR_RATS(
lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS(
LFSR_RAT(
LFSR_TAG_RM | LFSR_TAG_SUB | LFSR_TAG_STRUCT, 0,
LFSR_DATA_NULL()))) => 0;
@@ -1094,22 +1094,22 @@ code = '''
lfsr_file_sync(&lfs, &file) => 0;
// create an empty bshrub
lfsr_mdir_commit(&lfs, &file.o.o.mdir, LFSR_RATS(
lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS(
LFSR_RAT_SHRUBCOMMIT(
LFSR_TAG_SHRUBCOMMIT, 0,
&file.o.bshrub, 0, ((lfsr_rat_t[]){
&file.b.shrub, 0, ((lfsr_rat_t[]){
LFSR_RAT(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("?", 1))}),
1))) => 0;
lfsr_mdir_commit(&lfs, &file.o.o.mdir, LFSR_RATS(
lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS(
LFSR_RAT_SHRUBCOMMIT(
LFSR_TAG_SHRUBCOMMIT, 0,
&file.o.bshrub, 0, ((lfsr_rat_t[]){
&file.b.shrub, 0, ((lfsr_rat_t[]){
LFSR_RAT(LFSR_TAG_RM, -1, LFSR_DATA_NULL())}),
1))) => 0;
lfsr_mdir_commit(&lfs, &file.o.o.mdir, LFSR_RATS(
lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS(
LFSR_RAT_SHRUBTRUNK(
LFSR_TAG_SUB | LFSR_TAG_SHRUBTRUNK, 0,
&file.o.bshrub))) => 0;
&file.b.shrub))) => 0;
lfsr_file_close(&lfs, &file) => 0;
@@ -1224,16 +1224,16 @@ code = '''
// create an empty btree
lfs_alloc_ckpoint(&lfs);
lfsr_rbyd_alloc(&lfs, &file.o.bshrub) => 0;
lfsr_rbyd_commit(&lfs, &file.o.bshrub, 0, LFSR_RATS(
lfsr_rbyd_alloc(&lfs, &file.b.shrub) => 0;
lfsr_rbyd_commit(&lfs, &file.b.shrub, 0, LFSR_RATS(
LFSR_RAT(LFSR_TAG_DATA, +1, LFSR_DATA_BUF("?", 1)))) => 0;
lfsr_rbyd_commit(&lfs, &file.o.bshrub, 0, LFSR_RATS(
lfsr_rbyd_commit(&lfs, &file.b.shrub, 0, LFSR_RATS(
LFSR_RAT(LFSR_TAG_RM, -1, LFSR_DATA_NULL()))) => 0;
uint8_t buf[LFSR_BTREE_DSIZE];
lfsr_mdir_commit(&lfs, &file.o.o.mdir, LFSR_RATS(
lfsr_mdir_commit(&lfs, &file.b.o.mdir, LFSR_RATS(
LFSR_RAT(
LFSR_TAG_SUB | LFSR_TAG_BTREE, 0,
LFSR_DATA_BTREE(&file.o.bshrub, buf)))) => 0;
LFSR_DATA_BTREE(&file.b.shrub, buf)))) => 0;
lfsr_file_close(&lfs, &file) => 0;