Dropped the generalized lfs3_file_crystallize_ API
Eventually the generalized crystallize API may be useful again for the
"eager crystallization" write strategy, but the codebase has drifted
apart enough already that this will require some reimplementation
anyways (review the commit history!).
Might as well clean up API weirdness we're not using.
Saves surprisingly little code. I guess the compiler was able to
optimize out the duplicated args once the logic was a bit simpler?
code stack ctx
before: 37588 2472 656
after: 37580 (-0.0%) 2472 (+0.0%) 656 (+0.0%)
This commit is contained in:
@@ -12503,16 +12503,13 @@ failed:;
|
||||
// hot-path
|
||||
LFS3_NOINLINE
|
||||
static int lfs3_file_crystallize__(lfs3_t *lfs3, lfs3_file_t *file,
|
||||
lfs3_off_t block_pos,
|
||||
// TODO do we really need to keep crystal_min around? rename
|
||||
// to crystal_size?
|
||||
lfs3_ssize_t crystal_min, lfs3_ssize_t crystal_max,
|
||||
lfs3_off_t block_pos, lfs3_ssize_t crystal_size,
|
||||
lfs3_off_t pos, const uint8_t *buffer, lfs3_size_t size) {
|
||||
// align to prog_size, limit to block_size and theoretical file size
|
||||
lfs3_off_t crystal_limit = lfs3_min(
|
||||
block_pos + lfs3_min(
|
||||
lfs3_aligndown(
|
||||
(lfs3_off_t)crystal_max,
|
||||
(lfs3_off_t)crystal_size,
|
||||
lfs3->cfg->prog_size),
|
||||
lfs3->cfg->block_size),
|
||||
lfs3_max(
|
||||
@@ -12610,7 +12607,7 @@ static int lfs3_file_crystallize__(lfs3_t *lfs3, lfs3_file_t *file,
|
||||
// but make sure to include all of the requested
|
||||
// crystal if explicit, otherwise above loops
|
||||
// may never terminate
|
||||
&& (lfs3_soff_t)(pos_ - block_pos) >= crystal_min) {
|
||||
&& (lfs3_soff_t)(pos_ - block_pos) >= crystal_size) {
|
||||
// if we hit this condition, mark as crystallized,
|
||||
// attempting resume crystallization will not make
|
||||
// progress
|
||||
@@ -12741,13 +12738,13 @@ static int lfs3_file_crystallize__(lfs3_t *lfs3, lfs3_file_t *file,
|
||||
|
||||
#if !defined(LFS3_RDONLY) && !defined(LFS3_KVONLY) && !defined(LFS3_2BONLY)
|
||||
static int lfs3_file_crystallize_(lfs3_t *lfs3, lfs3_file_t *file,
|
||||
lfs3_off_t block_pos, lfs3_soff_t crystal_min, lfs3_soff_t crystal_max,
|
||||
lfs3_off_t block_pos, lfs3_ssize_t crystal_size,
|
||||
lfs3_off_t pos, const uint8_t *buffer, lfs3_size_t size) {
|
||||
// this is split into two functions to try to minimize stack usage
|
||||
|
||||
// crystallize
|
||||
int err = lfs3_file_crystallize__(lfs3, file,
|
||||
block_pos, crystal_min, crystal_max,
|
||||
block_pos, crystal_size,
|
||||
pos, buffer, size);
|
||||
if (err) {
|
||||
goto failed;
|
||||
@@ -12792,7 +12789,7 @@ static int lfs3_file_crystallize(lfs3_t *lfs3, lfs3_file_t *file) {
|
||||
lfs3_alloc_ckpoint(lfs3);
|
||||
// finish crystallizing
|
||||
int err = lfs3_file_crystallize_(lfs3, file,
|
||||
file->leaf.pos - lfs3_bptr_off(&file->leaf.bptr), -1, -1,
|
||||
file->leaf.pos - lfs3_bptr_off(&file->leaf.bptr), -1,
|
||||
file->cache.pos, file->cache.buffer, file->cache.size);
|
||||
if (err) {
|
||||
return err;
|
||||
@@ -12942,9 +12939,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
|
||||
file->b.o.flags |= LFS3_o_UNCRYST;
|
||||
// crystallize
|
||||
int err = lfs3_file_crystallize_(lfs3, file,
|
||||
block_start,
|
||||
(pos + size) - block_start,
|
||||
(pos + size) - block_start,
|
||||
block_start, (pos + size) - block_start,
|
||||
pos, buffer, size);
|
||||
if (err) {
|
||||
return err;
|
||||
@@ -13073,9 +13068,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
|
||||
file->b.o.flags |= LFS3_o_UNCRYST;
|
||||
// crystallize
|
||||
int err = lfs3_file_crystallize_(lfs3, file,
|
||||
block_start,
|
||||
crystal_end - block_start,
|
||||
crystal_end - block_start,
|
||||
block_start, crystal_end - block_start,
|
||||
pos, buffer, size);
|
||||
if (err) {
|
||||
return err;
|
||||
@@ -13140,9 +13133,7 @@ static int lfs3_file_flush_(lfs3_t *lfs3, lfs3_file_t *file,
|
||||
//
|
||||
// lfs3_file_crystallize_ handles block allocation/relocation
|
||||
err = lfs3_file_crystallize_(lfs3, file,
|
||||
crystal_start,
|
||||
crystal_end - crystal_start,
|
||||
crystal_end - crystal_start,
|
||||
crystal_start, crystal_end - crystal_start,
|
||||
pos, buffer, size);
|
||||
if (err) {
|
||||
return err;
|
||||
|
||||
Reference in New Issue
Block a user