Reverted the second mdir in lfsr_dir_t, simplified dir updates

This reverts the big hack of treating the lfsr_dir_t as an mdir array in
lfsr_mdir_commit in an effort to deduplicate the bookmark/pos mid
updates.

It worked, but lets be honest, it was a big hack and probably not very
maintainable. It made other opened-mdir updates, such as propagation of
unerases more complex, and is made the code a bit unreadable.

We also don't really need a full mdir for the dir's bookmark, since
rewinds really aren't that common, and a single mtree lookup in that
case gets the job done. Removing the bookmark mdir (though we still need
the bookmark mid to adjust the dir pos correctly) saves 24 bytes from
every lfsr_dir_t.

It would be nice to deduplicate some of the mid logic here, but that's
been difficult because of mid-related side-effects, such as updating the
mdir's pos. There may be room for improvement here.

---

This looks pretty bad, with the additional loop over the attr-list to
update just the dir's bookmark, but it's really not that bad when
compiled, and probably worth the code readability:

            code          stack          structs
  before:  20958           1744              864
  after:   21052 (+0.4%)   1744 (+0.0%)      840 (-2.9%)
This commit is contained in:
Christopher Haster
2023-09-10 12:58:00 -05:00
parent cced7d66ef
commit ba571cf83f
2 changed files with 122 additions and 88 deletions
+2 -7
View File
@@ -428,14 +428,9 @@ typedef struct lfs_dir {
} lfs_dir_t;
typedef struct lfsr_dir {
// the order is very sensitive here!
// this overlaps with:
// - lfsr_openedmdir_t
// - lfsr_mdir_t[2]
struct lfsr_openedmdir *next;
lfsr_mdir_t bookmark_mdir;
lfsr_mdir_t pos_mdir;
lfsr_openedmdir_t m;
lfs_size_t did;
lfs_ssize_t bookmark;
lfs_off_t pos;
} lfsr_dir_t;