rattrs: Adopted implicit lfs3_path_namelen in LFS3_FROM_NAME

I was poking around at possibly inlining small (<=255) name lens in
lfs3_rattr_t, but realized all LFS3_FROM_NAME rattrs in our system
already use the lfs3_path_namelen pattern (terminates in either
'\0' or '/').

Well, except for our tests, but who cares about those.

Adopting lfs3_path_namelen in LFS3_FROM_NAME saves a bit of code:

                 code          stack          ctx
  before:       35316           2176          660
  after:        35288 (-0.1%)   2176 (+0.0%)  660 (+0.0%)

                 code          stack          ctx
  gbmap before: 38168           2192          772
  gbmap after:  38140 (-0.1%)   2192 (+0.0%)  772 (+0.0%)
This commit is contained in:
Christopher Haster
2025-11-30 01:18:45 -06:00
parent a96e2776cb
commit 03df517dae
4 changed files with 226 additions and 316 deletions
+10 -12
View File
@@ -3254,6 +3254,7 @@ static int lfs3_rbyd_appendtag(lfs3_t *lfs3, lfs3_rbyd_t *rbyd,
#endif
// needed in lfs3_rbyd_appendrattr_
static inline lfs3_size_t lfs3_path_namelen(const char *path);
static lfs3_data_t lfs3_data_frombranch(const lfs3_rbyd_t *branch,
uint8_t buffer[static LFS3_BRANCH_DSIZE]);
static lfs3_data_t lfs3_data_frombtree(const lfs3_btree_t *btree,
@@ -3385,7 +3386,9 @@ static int lfs3_rbyd_appendrattr_(lfs3_t *lfs3, lfs3_rbyd_t *rbyd,
// name?
} else if (from == LFS3_FROM_NAME) {
ctx.u.name.datas[0] = lfs3_data_fromleb128(args[0], ctx.u.name.buf);
ctx.u.name.datas[1] = LFS3_DATA_BUF((const uint8_t*)args[1], args[2]);
ctx.u.name.datas[1] = LFS3_DATA_BUF(
(const char*)args[1],
lfs3_path_namelen((const char*)args[1]));
datas = ctx.u.name.datas;
data_count = 2;
@@ -11321,12 +11324,11 @@ int lfs3_mkdir(lfs3_t *lfs3, const char *path) {
// process
lfs3_grm_pop(lfs3);
err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS(
LFS3_RATTR(4, LFS3_tag_MASK12 | LFS3_TAG_DIR,
LFS3_RATTR(3, LFS3_tag_MASK12 | LFS3_TAG_DIR,
(tag == LFS3_ERR_NOENT) ? +1 : 0,
LFS3_FROM_NAME),
LFS3_RATTR_ARG(did),
LFS3_RATTR_ARG(name),
LFS3_RATTR_ARG(name_len),
LFS3_RATTR(2, LFS3_TAG_DID, 0, LFS3_FROM_LEB128),
LFS3_RATTR_ARG(did_),
LFS3_RATTR_NULL));
@@ -11474,12 +11476,11 @@ int lfs3_remove(lfs3_t *lfs3, const char *path) {
// we use a create+delete here to also clear any rattrs
// and trim the entry size
(zombie)
? LFS3_RATTR(4, LFS3_tag_MASK12 | LFS3_TAG_STICKYNOTE, 0,
? LFS3_RATTR(3, LFS3_tag_MASK12 | LFS3_TAG_STICKYNOTE, 0,
LFS3_FROM_NAME)
: LFS3_RATTR(4, LFS3_tag_RM, -1),
: LFS3_RATTR(3, LFS3_tag_RM, -1),
LFS3_RATTR_ARG(did),
LFS3_RATTR_ARG(path),
LFS3_RATTR_ARG(lfs3_path_namelen(path)),
LFS3_RATTR_NULL));
if (err) {
return err;
@@ -11650,12 +11651,11 @@ int lfs3_rename(lfs3_t *lfs3, const char *old_path, const char *new_path) {
// rename our entry, copying all tags associated with the old rid to the
// new rid, while also marking the old rid for removal
err = lfs3_mdir_commit(lfs3, &new_mdir, LFS3_RATTRS(
LFS3_RATTR(4, LFS3_tag_MASK12 | old_tag,
LFS3_RATTR(3, LFS3_tag_MASK12 | old_tag,
(new_tag == LFS3_ERR_NOENT) ? +1 : 0,
LFS3_FROM_NAME),
LFS3_RATTR_ARG(new_did),
LFS3_RATTR_ARG(new_path),
LFS3_RATTR_ARG(lfs3_path_namelen(new_path)),
LFS3_RATTR(2, LFS3_tag_MOVE, 0),
LFS3_RATTR_ARG(&old_mdir),
LFS3_RATTR_NULL));
@@ -12410,10 +12410,9 @@ int lfs3_file_opencfg_(lfs3_t *lfs3, lfs3_file_t *file,
file->b.h.flags |= LFS3_o_UNSYNC;
err = lfs3_file_sync_(lfs3, file, LFS3_RATTRS(
LFS3_RATTR(4, LFS3_TAG_REG, +1, LFS3_FROM_NAME),
LFS3_RATTR(3, LFS3_TAG_REG, +1, LFS3_FROM_NAME),
LFS3_RATTR_ARG(did),
LFS3_RATTR_ARG(path),
LFS3_RATTR_ARG(lfs3_path_namelen(path)),
LFS3_RATTR_NULL));
if (err) {
goto failed;
@@ -12423,10 +12422,9 @@ int lfs3_file_opencfg_(lfs3_t *lfs3, lfs3_file_t *file,
// create a stickynote entry if we don't have one, this
// reserves the mid until first sync
err = lfs3_mdir_commit(lfs3, &file->b.h.mdir, LFS3_RATTRS(
LFS3_RATTR(4, LFS3_TAG_STICKYNOTE, +1, LFS3_FROM_NAME),
LFS3_RATTR(3, LFS3_TAG_STICKYNOTE, +1, LFS3_FROM_NAME),
LFS3_RATTR_ARG(did),
LFS3_RATTR_ARG(path),
LFS3_RATTR_ARG(lfs3_path_namelen(path)),
LFS3_RATTR_NULL));
if (err) {
goto failed;