From b9ef43a30e481628ec12ef9af62306b7ff77a419 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 23 May 2025 23:12:54 -0500 Subject: [PATCH] Reused block_start/end in crystallize math Not sure how the duplication here went unnoticed. Note we can _not_ reuse block_start/end for the buffer updates, since those depend on the crystallized/aligned result. No code changes though. The good news is the compiler is doing a good job with the dense math in these functions. --- lfs.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lfs.c b/lfs.c index 71139937..9090de3a 100644 --- a/lfs.c +++ b/lfs.c @@ -12418,8 +12418,7 @@ static int lfsr_file_crystallize(lfs_t *lfs, lfsr_file_t *file) { // finish crystallizing the block int err = lfsr_file_crystallize_(lfs, file, - file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr), - -1, -1, + file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr), -1, -1, file->cache.pos, file->cache.buffer, file->cache.size); if (err) { return err; @@ -12482,11 +12481,9 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file, // need to bail if we can't meet prog alignment && (pos + size) - block_end >= lfs->cfg->prog_size) { int err = lfsr_file_crystallize_(lfs, file, - file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr), - (pos + size) - - (file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr)), - (pos + size) - - (file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr)), + block_start, + (pos + size) - block_start, + (pos + size) - block_start, pos, buffer, size); if (err) { return err; @@ -12612,11 +12609,9 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file, && crystal_start >= block_end && crystal_start < block_start + lfs->cfg->block_size) { int err = lfsr_file_crystallize_(lfs, file, - file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr), - crystal_end - - (file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr)), - crystal_end - - (file->leaf.pos - lfsr_bptr_off(&file->leaf.bptr)), + block_start, + crystal_end - block_start, + crystal_end - block_start, pos, buffer, size); if (err) { return err; @@ -12684,8 +12679,10 @@ static int lfsr_file_flush_(lfs_t *lfs, lfsr_file_t *file, // start crystallizing! // // lfsr_file_crystallize_ handles block allocation/relocation - err = lfsr_file_crystallize_(lfs, file, crystal_start, - crystal_end - crystal_start, crystal_end - crystal_start, + err = lfsr_file_crystallize_(lfs, file, + crystal_start, + crystal_end - crystal_start, + crystal_end - crystal_start, pos, buffer, size); if (err) { return err;