From fdfa7b5908b9c2825d4785157f145cc987414f49 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 19 Jan 2024 15:33:41 -0600 Subject: [PATCH] Avoid touching disk when out-of-bounds in lfsr_rbyd_lookupnext We really shouldn't go to disk in cases like these, it's not worth the code tradeoff. This led to concious decisions to avoid out-of-bound lookups in higher-layers, which sort of defeats any benefit of this potential optimization. code stack before: 33948 2944 after: 33956 (+0.0%) 2944 (+0.0%) --- lfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lfs.c b/lfs.c index dc077267..cd276e8b 100644 --- a/lfs.c +++ b/lfs.c @@ -2235,16 +2235,16 @@ static int lfsr_rbyd_lookupnext(lfs_t *lfs, const lfsr_rbyd_t *rbyd, // unreachable tags has a hole here tag = lfs_max16(tag, 0x1); + // out of bounds? no trunk yet? + if (rid >= rbyd->weight || !rbyd->trunk) { + return LFS_ERR_NOENT; + } + // keep track of bounds as we descend down the tree lfs_size_t branch = rbyd->trunk; lfsr_srid_t lower = 0; lfsr_srid_t upper = rbyd->weight; - // no trunk yet? - if (!branch) { - return LFS_ERR_NOENT; - } - // descend down tree while (true) { lfsr_tag_t alt;