Fixed double-checking of btree nodes with ckfetches + ckmeta

No reason to check every btree node twice!

This adds a bit of code in the ckfetches case, but it's well worth it to
avoid unnecessary checks.

It would actually have saved code if ckfetches were unconditional, but
ckfetches are currently still behind a runtime flag even when enabled:

                     code          stack
  default before:   36432           2672 (+0.0%)
  default after:    36432 (+0.0%)   2672 (+0.0%)

  ckfetches before: 36674           2704
  ckfetches after:  36682 (+0.0%)   2704 (+0.0%)
This commit is contained in:
Christopher Haster
2024-08-14 16:48:30 -05:00
parent 2cefcbdddc
commit 3b11e980e2
+10 -2
View File
@@ -9474,6 +9474,10 @@ static int lfsr_mtree_traverse(lfs_t *lfs, lfsr_traversal_t *t,
// validate btree nodes? note mdirs are already validated
if ((lfsr_t_isckmeta(t->o.o.flags)
|| lfsr_t_isckdata(t->o.o.flags))
// note ckfetches already validates btree nodes
&& LFS_IFDEF_CKFETCHES(
!lfsr_m_isckfetches(lfs->flags),
true)
&& tag == LFSR_TAG_BRANCH) {
lfsr_rbyd_t *rbyd = (lfsr_rbyd_t*)bptr.data.u.buffer;
err = lfsr_rbyd_fetchck(lfs, rbyd,
@@ -9534,8 +9538,8 @@ dropped:;
// mkconsistencing mdirs?
if (lfsr_t_ismkconsistent(t->o.o.flags)
&& tag == LFSR_TAG_MDIR
&& lfsr_i_hasorphans(lfs->flags)) {
&& lfsr_i_hasorphans(lfs->flags)
&& tag == LFSR_TAG_MDIR) {
lfsr_mdir_t *mdir = (lfsr_mdir_t*)bptr.data.u.buffer;
err = lfsr_fs_fixorphans_(lfs, mdir);
if (err) {
@@ -12636,6 +12640,10 @@ static int lfsr_file_ck(lfs_t *lfs, const lfsr_file_t *file,
// validate btree nodes?
if ((lfsr_t_isckmeta(flags)
|| lfsr_t_isckdata(flags))
// note ckfetches already validates btree nodes
&& LFS_IFDEF_CKFETCHES(
!lfsr_m_isckfetches(lfs->flags),
true)
&& tag == LFSR_TAG_BRANCH) {
lfsr_rbyd_t *rbyd = (lfsr_rbyd_t*)bptr.data.u.buffer;
err = lfsr_rbyd_fetchck(lfs, rbyd,