rattrs: Reverted implicit lfs3_path_namelen in LFS3_FROM_NAME
I don't think there was anything inherently wrong with this idea, but:
- The code savings (28 bytes) was surprisingly small.
- Expecting lfs3_path_namelen may be a headache for future
non-null-terminated string support.
- Even if you don't care about non-null-terminated strings, precomputing
strlen as early as possible is a good idea to minimize repeated strlen
scans.
Reverting adds a bit of code:
code stack ctx
before: 35288 2176 660
after: 35316 (+0.1%) 2176 (+0.0%) 660 (+0.0%)
code stack ctx
gbmap before: 38140 2192 772
gbmap after: 38168 (+0.1%) 2192 (+0.0%) 772 (+0.0%)
This commit is contained in:
@@ -3254,7 +3254,6 @@ 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,
|
||||
@@ -3386,9 +3385,7 @@ 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 char*)args[1],
|
||||
lfs3_path_namelen((const char*)args[1]));
|
||||
ctx.u.name.datas[1] = LFS3_DATA_BUF((const uint8_t*)args[1], args[2]);
|
||||
datas = ctx.u.name.datas;
|
||||
data_count = 2;
|
||||
|
||||
@@ -11324,11 +11321,12 @@ int lfs3_mkdir(lfs3_t *lfs3, const char *path) {
|
||||
// process
|
||||
lfs3_grm_pop(lfs3);
|
||||
err = lfs3_mdir_commit(lfs3, &mdir, LFS3_RATTRS(
|
||||
LFS3_RATTR(3, LFS3_tag_MASK12 | LFS3_TAG_DIR,
|
||||
LFS3_RATTR(4, 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));
|
||||
@@ -11476,11 +11474,12 @@ 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(3, LFS3_tag_MASK12 | LFS3_TAG_STICKYNOTE, 0,
|
||||
? LFS3_RATTR(4, LFS3_tag_MASK12 | LFS3_TAG_STICKYNOTE, 0,
|
||||
LFS3_FROM_NAME)
|
||||
: LFS3_RATTR(3, LFS3_tag_RM, -1),
|
||||
: LFS3_RATTR(4, 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;
|
||||
@@ -11651,11 +11650,12 @@ 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(3, LFS3_tag_MASK12 | old_tag,
|
||||
LFS3_RATTR(4, 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,9 +12410,10 @@ 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(3, LFS3_TAG_REG, +1, LFS3_FROM_NAME),
|
||||
LFS3_RATTR(4, 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;
|
||||
@@ -12422,9 +12423,10 @@ 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(3, LFS3_TAG_STICKYNOTE, +1, LFS3_FROM_NAME),
|
||||
LFS3_RATTR(4, 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;
|
||||
|
||||
Reference in New Issue
Block a user