Skip flushing file if lfs_file_rawseek() doesn't change position
This commit is contained in:
@@ -3048,14 +3048,6 @@ relocate:
|
|||||||
|
|
||||||
static lfs_soff_t lfs_file_rawseek(lfs_t *lfs, lfs_file_t *file,
|
static lfs_soff_t lfs_file_rawseek(lfs_t *lfs, lfs_file_t *file,
|
||||||
lfs_soff_t off, int whence) {
|
lfs_soff_t off, int whence) {
|
||||||
#ifndef LFS_READONLY
|
|
||||||
// write out everything beforehand, may be noop if rdonly
|
|
||||||
int err = lfs_file_flush(lfs, file);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// find new pos
|
// find new pos
|
||||||
lfs_off_t npos = file->pos;
|
lfs_off_t npos = file->pos;
|
||||||
if (whence == LFS_SEEK_SET) {
|
if (whence == LFS_SEEK_SET) {
|
||||||
@@ -3071,6 +3063,19 @@ static lfs_soff_t lfs_file_rawseek(lfs_t *lfs, lfs_file_t *file,
|
|||||||
return LFS_ERR_INVAL;
|
return LFS_ERR_INVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (file->pos == npos) {
|
||||||
|
// noop - position has not changed
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef LFS_READONLY
|
||||||
|
// write out everything beforehand, may be noop if rdonly
|
||||||
|
int err = lfs_file_flush(lfs, file);
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// update pos
|
// update pos
|
||||||
file->pos = npos;
|
file->pos = npos;
|
||||||
return npos;
|
return npos;
|
||||||
|
|||||||
Reference in New Issue
Block a user