Adopted lazy encoding for le32 and leb128 attrs

- LFSR_TAG_RCOMPAT     -+-> lfsr_data_fromle32
- LFSR_TAG_WCOMPAT     -+
- LFSR_TAG_OCOMPAT     -+
- LFSR_TAG_GCKSUMDELTA -'
- LFSR_TAG_NAMELIMIT   -+-> lfsr_data_fromleb128
- LFSR_TAG_FILELIMIT   -+
- LFSR_TAG_BOOKMARK    -+
- LFSR_TAG_DID         -'

This is nice mainly from an internal API standpoint. Single le32/leb128
attrs should be pretty lightweight, and it's nice for the API to reflect
that.

With a bit of tinkering with the internal lfsr_rattr_t type, we can even
pass these directly in the lfsr_rattr_t struct itself, so no need to
keep single le32/leb128 attrs on the stack:

  buffer rattr:        cat attr:            le32/leb128 attr:
  .---+---+---+---. .. .---+---+---+---. .. .---+---+---+---.
  |  tag  |0|size |    |  tag  |1|count|    |  tag  |0|dsize|
  +---+---+---+---+    +---+---+---+---+    +---+---+---+---+
  |     weight    |    |     weight    |    |     weight    |
  +---+---+---+---+ .. +---+---+---+---+ .. +---+---+---+---+
  |      ptr -------.  |      ptr -------.  |  le32/leb128  |
  '---+---+---+---' |  '---+---+---+---' |  '---+---+---+---'
  .---+---+---+---. |  .---+---+---+---. |
  |      data     |<'  |mm|   size     |<'
  :       :       :    +---+---+---+---+
                       |      data     |
                       +               +
                       |               |
                       +---+---+---+---+
                       |mm|   size     |
                       :       :       :

While tinkering I also ended up renaming a couple things:

- rattr.cat -> rattr.u.datas, rattr.u.buffer, rattr.u.etc
- rattr.count -> rattr.data_count
- added lfsr_rattr_dtag for ignoring on-disk/explicit-data tags
- lfsr_rattr_size -> lfsr_rattr_dsize

Surprisingly very little code savings though. I guess we don't use
single le32/leb128 attrs enough to overcome the added complexity to
lfsr_rbyd_appendrattr_'s switch-case-table?

           code          stack          ctx
  before: 35636           2440          636
  after:  35632 (-0.0%)   2440 (+0.0%)  636 (+0.0%)

That or there's something else weird going on with this union and
compiler assumptions. Attempting to adopt .u.etc in LFSR_RATTR__ alone
adds ~100 bytes of code, even though both .u.etc and .u.cat are the same
type (const void *)...

Not entirely sure what's going on...
This commit is contained in:
Christopher Haster
2025-02-09 23:47:12 -06:00
parent 3e662e0b52
commit e15412d1d6
2 changed files with 187 additions and 104 deletions
+2 -3
View File
@@ -1055,11 +1055,10 @@ code = '''
// note we're messing around with internals to do this! this
// is not a user API
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
uint8_t name_limit_buf[LFSR_LLEB128_DSIZE];
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATTRS(
LFSR_RATTR(
LFSR_RATTR_LEB128__(
LFSR_TAG_NAMELIMIT, 0,
LFSR_DATA_LLEB128(INC_NAME_LIMIT, name_limit_buf)))) => 0;
INC_NAME_LIMIT))) => 0;
lfsr_unmount(&lfs) => 0;
// mount should now fail