Made grm a special attribute, moved encoding into mdir commit

This is entirely a pragmatic change, lfsr_mdir_commit already does
several hairy things with grm tags, decoding, fixing, reencoding, etc,
so it makes sense to move all the encoding logic into lfsr_mdir_commit.

This leads to a couple optimizations:

- We don't need to decode the grm to apply any last minute fixes.

- By allowing the grm arugment to be mutated (they are just sitting on
  the stack anyways, we need a copy in case we back out of change due to
  error), we can apply and save any grm fixes in the grm argument
  itself.

  This means we only need to fix the grm at most once, after any mtree
  modifications.

Which in turn saves some code and stack cost:

            code          stack
  before:  22930           2392
  after:   22706 (-1.0%)   2344 (-2.0%)
This commit is contained in:
Christopher Haster
2023-07-28 16:04:43 -05:00
parent 4cf5509c91
commit e08ff99d50
3 changed files with 217 additions and 246 deletions
+77 -77
View File
@@ -24,7 +24,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked with stat
@@ -74,7 +74,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -120,7 +120,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -170,7 +170,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -226,7 +226,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -280,7 +280,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -331,7 +331,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -394,7 +394,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -479,7 +479,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -542,7 +542,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -611,7 +611,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
}
@@ -718,7 +718,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
}
@@ -846,7 +846,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -948,7 +948,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// test that our directories match our simulation
@@ -1027,7 +1027,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -1122,7 +1122,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -1219,7 +1219,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -1316,7 +1316,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -1396,7 +1396,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked with stat
@@ -1428,7 +1428,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that remove worked with stat
@@ -1479,7 +1479,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -1534,7 +1534,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -1607,7 +1607,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -1658,7 +1658,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -1701,7 +1701,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our remove worked
@@ -1737,7 +1737,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our remove worked
@@ -1768,7 +1768,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our remove worked
@@ -1814,7 +1814,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -1877,7 +1877,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our remove worked
@@ -1933,7 +1933,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our remove worked
@@ -1974,7 +1974,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our remove worked
@@ -2027,7 +2027,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -2070,7 +2070,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -2142,7 +2142,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -2185,7 +2185,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -2264,7 +2264,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -2341,7 +2341,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -2356,7 +2356,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -2475,7 +2475,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -2584,7 +2584,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -2599,7 +2599,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -2614,7 +2614,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -2760,7 +2760,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -2808,7 +2808,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -2928,7 +2928,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// test that our directories match our simulation
@@ -2997,7 +2997,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked with stat
@@ -3029,7 +3029,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that rename worked with stat
@@ -3079,7 +3079,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked with stat
@@ -3114,7 +3114,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that rename worked with stat
@@ -3162,7 +3162,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked with stat
@@ -3194,7 +3194,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that rename worked with stat
@@ -3253,7 +3253,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -3309,7 +3309,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -3385,7 +3385,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// and check that this didn't interfere with our original directory
@@ -3446,7 +3446,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -3489,7 +3489,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our rename worked
@@ -3530,7 +3530,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our rename worked
@@ -3571,7 +3571,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our rename worked
@@ -3648,7 +3648,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -3711,7 +3711,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our rename worked
@@ -3772,7 +3772,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our rename worked
@@ -3833,7 +3833,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our rename worked
@@ -3922,7 +3922,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -3969,7 +3969,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -4037,7 +4037,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -4084,7 +4084,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
@@ -4159,7 +4159,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -4237,7 +4237,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
for (lfs_size_t j = 0; j < N; j++) {
@@ -4256,7 +4256,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
}
@@ -4371,7 +4371,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdirs worked
@@ -4480,7 +4480,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
for (lfs_size_t j = 0; j < N; j++) {
@@ -4499,7 +4499,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
for (lfs_size_t k = 0; k < N; k++) {
@@ -4520,7 +4520,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
}
}
@@ -4660,7 +4660,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// check that our mkdir worked
@@ -4716,7 +4716,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// update old_name's path
@@ -4863,7 +4863,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// test that our directories match our simulation
@@ -5018,7 +5018,7 @@ code = '''
lfsr_unmount(&lfs) => 0;
lfsr_mount(&lfs, cfg) => 0;
// grm should be zero here
assert(lfs.grm[0] == 0);
assert(lfs.pgrm[0] == 0);
}
// test that our directories match our simulation