From be3e61dd13c6ee0b6232f4c115fc7599be132c42 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 4 Aug 2025 15:57:32 -0500 Subject: [PATCH] Dropped lfs3_file_weight_ Now that ungrafted leaves are much more limited in scope, I'm not sure lfs3_file_weight_ still makes sense as a separate function. The only call was in lfs3_file_read, where we decide if we bother flushing things before actually flushing things. Given that we should now generally graft before expecting lfs3_file_lookupnext to make sense, relying on lfs3_file_weight_ too much probably hints at a logic mistake. This logic ends up inlined anyways, so no code changes: code stack ctx before: 36992 2352 684 after: 36992 (+0.0%) 2352 (+0.0%) 684 (+0.0%) --- lfs3.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lfs3.c b/lfs3.c index 1f5af482..bbce621d 100644 --- a/lfs3.c +++ b/lfs3.c @@ -12499,20 +12499,18 @@ static inline lfs3_size_t lfs3_file_cachesize(lfs3_t *lfs3, : lfs3->cfg->file_cache_size; } -static inline lfs3_off_t lfs3_file_weight_(const lfs3_file_t *file) { +static inline lfs3_off_t lfs3_file_size_(const lfs3_file_t *file) { #ifndef LFS3_KVONLY return lfs3_max( - file->leaf.pos + file->leaf.weight, - file->b.shrub.r.weight); + file->cache.pos + file->cache.size, + lfs3_max( + file->leaf.pos + file->leaf.weight, + file->b.shrub.r.weight)); #else - return file->b.shrub.r.weight; - #endif -} - -static inline lfs3_off_t lfs3_file_size_(const lfs3_file_t *file) { return lfs3_max( - LFS3_IFDEF_KVONLY(0, file->cache.pos) + file->cache.size, - lfs3_file_weight_(file)); + file->cache.size, + file->b.shrub.r.weight); + #endif } @@ -13087,7 +13085,9 @@ lfs3_ssize_t lfs3_file_read(lfs3_t *lfs3, lfs3_file_t *file, } // any data in our btree? - if (pos_ < lfs3_file_weight_(file)) { + if (pos_ < lfs3_max( + file->leaf.pos + file->leaf.weight, + file->b.shrub.r.weight)) { if (!lfs3_o_isuncryst(file->b.h.flags) && !lfs3_o_isungraft(file->b.h.flags)) { // bypass cache?